UITableView не перезагружается должным образом - PullRequest
0 голосов
/ 15 апреля 2011

решаемые

Мое табличное представление не обновило данные должным образом. Проблема заключалась в том, что я поместил части редактирования содержимого текстовой метки в условное выражение "if (cell == nil)".

до

{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.textLabel.font = [UIFont boldSystemFontOfSize:16];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:12];

        //This is where the mistake was
        cell.textLabel.text = [[array objectAtIndex:indexPath.row] valueForKey:@"Key1"];

    if ([[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue] == 1)
    { cell.detailTextLabel.text =
        [NSString stringWithFormat:@"%d sometext (%d sometext), %d sometext",
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue],
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key3"] intValue],
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key4"] intValue]]; }
    else { cell.detailTextLabel.text =
        [NSString stringWithFormat:@"%d sometext (%d sometext), %d sometext",
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue],
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key3"] intValue],
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key4"] intValue]]; }
    }

    return cell;
}

ПОСЛЕ

{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.textLabel.font = [UIFont boldSystemFontOfSize:16];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
    }

    //This is what it should have looked like in the first place
    cell.textLabel.text = [[array objectAtIndex:indexPath.row] valueForKey:@"Key1"];

    if ([[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue] == 1)
    { cell.detailTextLabel.text =
        [NSString stringWithFormat:@"%d sometext (%d sometext), %d sometext",
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue],
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key3"] intValue],
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key4"] intValue]]; }
    else { cell.detailTextLabel.text =
        [NSString stringWithFormat:@"%d sometext (%d sometext), %d sometext",
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue],
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key3"] intValue],
         [[[array objectAtIndex:indexPath.row] valueForKey:@"Key4"] intValue]]; }
    return cell;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...