搜索显示控制器始终返回true,包含更多单元格

时间:2014-08-21 15:23:45

标签: ios7 uisearchdisplaycontroller

我正在尝试使用UISearchDisplayController来过滤掉表视图中的单元格,但是当我有少于7个单元格时,哪些单元格可以正常工作。一旦我尝试搜索具有超过7个单元格的视图控制器,应用程序就会崩溃,因为self.searchDisplayController.active在我开始输入之前总是返回true。

以下是我的应用崩溃的代码段:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    SubRefCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"TableCell"forIndexPath:indexPath];

    if (cell == nil) {
        NSLog(@"cell is nill");
        cell = [[SubRefCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableCell"];
    }

    int row=[indexPath row];

    if (self.searchDisplayController.active) { //is always true when more than 7 cells
        NSLog(@"Here is the table of results: %@",self.searchResults);
        cell.subRefLabel.text = self.searchResults[row];
        NSLog(@"failed ");
        cell.subRefDescLabel.text = _Refs.SubRefDesc[row]; //fix later


    } else {
        //set all the cells with the Sub Reference names and their descriptions
        cell.subRefLabel.text = _Refs.SubReference[row];
        cell.subRefDescLabel.text = _Refs.SubRefDesc[row];
    }

    return cell;
}

在其他情况下,我的单元格少于7个,self.searchDisplayController.active将返回false,直到我开始在搜索栏中输入。

这是我得到的错误: * -[__NSArrayI objectAtIndex:]: index 7 beyond bounds for empty array'*

为什么只要有超过iphone屏幕尺寸的单元格可以查看,searchDisplayController.active就为true?

0 个答案:

没有答案
相关问题