将Cell添加到UISearchDisplayController的tableview

时间:2014-09-07 21:09:18

标签: ios uitableview uisearchbar uisearchbardisplaycontrol

我有searchDisplayController的tableview。当我搜索一些文本时,我成功地在屏幕上显示结果。当我想在现有结果中添加单元格时,我的问题出现了。当searchDisplayController处于活动状态时,必须添加一个单元格。

那是:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        NSMutableDictionary * dict ;
        BOOL isSearchView = tableView == self.searchDisplayController.searchResultsTableView;
        if (isSearchView) {
            dict = [searchTasks objectAtIndex:indexPath.row];
            [self.searchDisplayController.searchResultsTableView deselectRowAtIndexPath:indexPath
                                                                               animated:YES];
        }
        else{
            dict = [self.tasks objectAtIndex:indexPath.row];
            [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
        }
            Task * task = [self getsomeTask];
            NSIndexPath *  ip = [NSIndexPath indexPathForRow:indexPath.row+1  
inSection:indexPath.section];
            if (isSearchView) {
                [searchTasks insertObject:task atIndex:ip.row];
                [self.searchDisplayController.searchResultsTableView  
                                        insertRowsAtIndexPaths:@[ip]
                                        withRowAnimation:UITableViewRowAnimationRight];

    }

执行此操作后,在最后一行insertRowsAtIndexPaths:@[ip]之后

代码执行:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.searchDisplayController.isActive) {
        return [searchTasks count];
    } else {
        return [tasks count];
    }
}

哪个好,这里根据程序逻辑选择第一个选项。但它崩溃了,在执行之后它从不调用

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

委托UITableview的功能。

并给我错误:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

我无法理解它在rowcount函数之后没有调用cellForRowAtIndexPath函数的原因。

有什么建议吗?

0 个答案:

没有答案