Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何不返回UITableviewCell_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 如何不返回UITableviewCell

Ios 如何不返回UITableviewCell,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个NSDictionary数组,在这个数组中有几个我不想在UITableView中显示的值,我想知道如何避免在表视图中返回这些单元格:cellForRowAtIndexPath: 我试图返回nil但这导致了我的错误 这就是我的代码的样子 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *Ce

我有一个NSDictionary数组,在这个数组中有几个我不想在UITableView中显示的值,我想知道如何避免在表视图中返回这些单元格:cellForRowAtIndexPath:

我试图
返回nil但这导致了我的错误

这就是我的代码的样子

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    CustomInstallCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[CustomInstallCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    currentInstallDictionary = [sortedItemsArray objectAtIndex:indexPath.row];

        NSNumber *tempDP = [currentInstallDictionary objectForKey:@"dp"];
        NSInteger myInteger = [tempDP integerValue];

        if (myInteger == 0) {

return cell;
}
return nil; // gives error
}

任何帮助都将不胜感激。

此方法必须返回单元格。它不能返回零。最好的做法是在加载表之前过滤列表,并在单元格出列时使用过滤后的数组

UITableView只请求一个单元格,因为您让它请求。协议的实现实现了两种方法:

在这些方法中,您可以确定屏幕上应该显示多少单元格。正如Brian Shamblen回答的那样,如果您不希望该数据出现在表视图中,那么在计算节数和行数时,您应该如何忽略(过滤、删除等)该数据。如果这样做,则不会请求“额外”单元格