如何不连续返回细胞



在我的- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中,是否可以不使用某些单元格填充表视图?

现在我的方法看起来像这样:

static NSString *CellIdentifier = @"Cell";
    ResultsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.title.text = [[resultsForCell objectAtIndex:indexPath.row] objectForKey:@"title"];
return cell;

但我想这样做,如果objectforkey@"title"等于某个值,则不在表视图中显示或不返回该单元格。我不知道怎样才能做到这一点。

如果要"过滤"表视图,则需要过滤源数据。在这种情况下,您需要从resultsForCell中删除这些值。

如果你想隐藏这些单元格上的标签,你可以将标签的隐藏设置为true。

定义您不想显示任何内容的indexPath值。然后在if块中使用上面方法中定义的值。例如:

如果您选择indexPathArray(1,3,5,6)作为不显示行的预定义数组,

if(![indexPathArray containsObject:indexPath]){
//your code for Showing cells title.
}

最新更新