如果包含特定字符串,如何在表视图中显示单元格?

时间:2011-09-03 13:57:11

标签: iphone xcode cell tableview show

我希望tableView不加载包含某些字符串的单元格,该怎么做?

static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

NSString *itemTitle = item.title;

        if ([item.title isEqualToString: @"Some string"])
{
   // Help needed
}
        else
{
        cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
        cell.textLabel.text =itemTitle;
}
    return cell;

1 个答案:

答案 0 :(得分:0)

  1. 一个可能的选项是保存您在加载表时不希望在屏幕上显示的单元格的indexPath,并在加载完成后使用以下方法将它们删除为表格。
  2. - (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

    1. 更好的选择是在加载表格之前更新您的数据。

    2. 如果以上两种方法都失败,那么您可以尝试以下方法 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

    3. 如果您不希望细胞出现在屏幕上,请返回0。可能不会出现高度为0的单元格。

      如果以上不起作用,请在此发布,以便我可以进一步协助....