Alex Rivera | Logout

UITableView clear data

Asked 2009-08-31T10:27:16.673
10

How to clear whole tableview data and reload with new one?

Edit
Report

1 Answer

0

You can look at the value of the reused cell and if its not the same - then recreate it.

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyLog(@"Start Table: cellForRowAtIndexPath: %d", indexPath.row);

NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier %i", indexPath.row];
UILabel *lblNew;
lblNew = [UILabel new];
UILabel *lblCell;
lblCell = [UILabel new];

MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil) 
{
    cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
    [cell.contentView addSubview:[lblNameArray objectAtIndex:indexPath.row]];       
} 
else 
{
    lblNew = [lblNameArray objectAtIndex:indexPath.row];
    for (id label in [cell.contentView subviews])   
    {
        if ([label isKindOfClass:[UILabel class]]) 
        {
            lblCell = label;
        }
    }
    if (![lblNew.text isEqualToString:lblCell.text])
    {
        cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
        [cell.contentView addSubview:[lblNameArray objectAtIndex:indexPath.row]];
    }
}
return cell;
answered 2011-04-02T09:46:04.233

Your Answer