просмотр таблицы :: не удалось удалить пользовательский ярлык в пользовательской ячейке - PullRequest
0 голосов
/ 29 декабря 2011

В моем приложении для iPhone

В табличном представлении

У меня есть две метки в одной ячейке.

  1. textLabel, которая по умолчанию.
  2. Пользовательская метка

Данные удаляются из массива, что нормально ...

Вот код ..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    //Get the Log Id for the sections. From Section Array
    int logID=0;
    if(indexPath.row==0)
    {
        NSLog(@"Time Array %@",timeArray);
        logID=[[[sectionArray objectAtIndex:indexPath.section] valueForKey:@"logID"] intValue];
        NSPredicate *p=[NSPredicate predicateWithFormat:@"logID==%d",logID];
        fillRows=nil;
        fillRows= [[timeArray filteredArrayUsingPredicate:p] mutableCopy];
    }



    static NSString *CellIdentifier = @"Cell";



    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

    }



//Show Current Time.
//"If condition for not to go for Array Index Out of Bound".
if(indexPath.row<[fillRows count])
{
//Log CurrentTime    
    cell.textLabel.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logCurrentTime"];
    [cell.textLabel setTextColor:[UIColor whiteColor]];
//Log Duration.   
   UILabel *lblDuration=[[[UILabel alloc] initWithFrame:CGRectMake(110, 11, 60, 21)] autorelease];
   [lblDuration setTextColor:[UIColor whiteColor]];
        [lblDuration setBackgroundColor:[UIColor clearColor]];
        [lblDuration setFont:[UIFont boldSystemFontOfSize:18]];
   lblDuration.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logDuration"];
        [cell.contentView addSubview:lblDuration];
   }

    return cell;
}

Заранее спасибо :)

Ответы [ 3 ]

0 голосов
/ 29 декабря 2011

используйте метод делегата таблицы для вашего решения

  • (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editStyle forRowAtIndexPath: (NSIndexPath *) indexPath { if (editStyle == UITableViewCellEditingStyleDelete) {[array removeObjectAtIndex: indexPath.row]; [tableview reloadData];}}

ты получаешь то, что хочешь.

0 голосов
/ 29 декабря 2011

Ответ таков: вот почему метка ячейки, которая была удалена из таблицы, застряла в ячейке ...

Только посмотрите, я прокомментировал две строки кода ......

Где ячейка == ноль ..

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

        //Get the Log Id for the sections. From Section Array

        static NSString *CellIdentifier = @"Cell";



        **UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     //   if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

       // }**



    /if(indexPath.row<[fillRows count])
    {
    //Log CurrentTime    
        cell.textLabel.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logCurrentTime"];
        [cell.textLabel setTextColor:[UIColor whiteColor]];
    //Log Duration.   
       UILabel *lblDuration=[[[UILabel alloc] initWithFrame:CGRectMake(110, 11, 60, 21)] autorelease];
       [lblDuration setTextColor:[UIColor whiteColor]];
            [lblDuration setBackgroundColor:[UIColor clearColor]];
            [lblDuration setFont:[UIFont boldSystemFontOfSize:18]];
       lblDuration.text=[[fillRows objectAtIndex:indexPath.row] valueForKey:@"logDuration"];
            [cell.contentView addSubview:lblDuration];
       }

        return cell;
    }
0 голосов
/ 29 декабря 2011
  if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
   }
 if(indexPath.row<[fillRows count])
 {
        [lblDuration setTextColor:[UIColor whiteColor]];
        [lblDuration setBackgroundColor:[UIColor clearColor]];
        [lblDuration setFont:[UIFont boldSystemFontOfSize:18]];
        [cell.contentView addSubview:lblDuration];

 }

Попробуйте это ..

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...