Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.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 UITableView在不调用数据源的情况下重新绘制_Ios_Uitableview_Uisearchdisplaycontroller - Fatal编程技术网

Ios UITableView在不调用数据源的情况下重新绘制

Ios UITableView在不调用数据源的情况下重新绘制,ios,uitableview,uisearchdisplaycontroller,Ios,Uitableview,Uisearchdisplaycontroller,使用UISearchDisplayController是否可以调用tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath方法,而不调用实际行数的数据源 以下是崩溃的堆栈跟踪(iOS 7.1.2): 据我所知,搜索栏编辑字段中有一个点击,搜索开始了。若数据源中的行数正确,则不可能出现这种异常。所以我的建议是,数据源并没有被要求提供行数 以下是我的数据源实现: - (NSInteger)tableVie

使用
UISearchDisplayController
是否可以调用
tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath
方法,而不调用实际行数的数据源

以下是崩溃的堆栈跟踪(iOS 7.1.2):

据我所知,搜索栏编辑字段中有一个点击,搜索开始了。若数据源中的行数正确,则不可能出现这种异常。所以我的建议是,数据源并没有被要求提供行数

以下是我的数据源实现:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_searchDisplayController.active)
    {
        // return number of search items
    }

    // return number of regular items in section
}
我使用
active
属性了解是否需要提供搜索项目的数量而不是常规项目。我的另一个建议是,出于某种原因,搜索控制器在数据源调用时不处于活动状态,但在表委托调用时处于活动状态

是的。对于
tableView:(UITableView*)tableView cellforrowatinedexpath:(nsindepath*)indepath
,您可以只返回一个空单元格,而不表示数据源

tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    return cell;
}

您的崩溃是由
BaseContactsViewController.m:338
引起的。您正试图从空数据集中获取索引为0的对象。这行有什么内容?

如果numberOfSectionsInTableView:返回零,cellForRowAtIndexPath:将不调用,请确认。所以不可能有空数组索引异常。你在文章中的建议是正确的。UISearchDisplayController不调用numberOfSectionsInTableView:如果在其中设置断点,它不会中断。我在我的一个项目中体验到了这一点。我希望避免UISearchDisplayController出现这种混乱。我想我现在明白你的问题了。对于这个问题,我认为不可能在不调用实际行数的数据源的情况下调用tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath。
tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    return cell;
}