Ios7 “搜索显示控制器”始终返回“真”和更多单元格
我正在尝试使用Ios7 “搜索显示控制器”始终返回“真”和更多单元格,ios7,uisearchdisplaycontroller,Ios7,Uisearchdisplaycontroller,我正在尝试使用UISearchDisplayController过滤出表视图中的单元格,但当我的单元格少于7个(与iphone屏幕大小相当)时,这种方法就可以正常工作。当我试图搜索超过7个单元格的视图控制器时,应用程序就会崩溃,因为在我开始键入之前,self.searchDisplayController.active总是返回true 下面是我的应用程序崩溃的代码片段: - (UITableViewCell *)tableView:(UITableView *)tableView cellFor
UISearchDisplayController
过滤出表视图中的单元格,但当我的单元格少于7个(与iphone屏幕大小相当)时,这种方法就可以正常工作。当我试图搜索超过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,直到我开始在搜索栏中键入
以下是我得到的错误:
*-[\uu NSArrayI objectAtIndex:]:索引7超出空数组的界限'*
为什么当有超过iphone屏幕大小的单元格时,searchDisplayController.active会为真?在每个TVC数据源方法中,您是否正在检查是否为主表视图
self.tableView
或UISearchDisplayController
表视图self.searchDisplayController.searchResultsTableView
提供信息?