UISearchDisplayController - 为什么我的搜索结果视图包含空单元格?

Jac*_*ald 6 iphone uisearchdisplaycontroller nsfetchedresultscontroller

我即将离开这里,在我的Core Data数据库中我有很多用户,我已经通过NSFetchedResultController将数据库连接到tableviewcontroller,当视图加载时,我看到所有用户,我可以通过storyboard segue执行推送到详细视图控制器...到目前为止,所以上帝,我的tableview包含一个带有图像视图的自定义单元格和2个uitextlabels,它们都分配了标签值.

现在,当我执行搜索时,我创建了一个带有谓词的新NSFetchedResultController,并执行performFetch ..然后我获取fetchedObjects属性并且它包含匹配的用户,因此搜索请求也像魅力一样...我的tableviews数据源我检查self.tableView == self.searchdispl.view以查看我应该从哪个控制器查询数据..在所有控制器委托中,我检查哪个控制器是活动的,所以我知道要重新加载哪个视图.如果我记录了很多数据,那么幕后操作就很好了,委托和数据源方法都使用了正确的视图和fetchcontroller.

在我的cellForRowAtIndexPath中,我可以注销我的user.name,这在搜索时也是正确的.

问题是顶部的UISearchDisplayController视图只有空单元格,除非我将UITableViewControllers动态原型单元格设置为basic,然后两个tableviews都包含带有用户名称的标签!来自单元格的segue仍然不起作用,但是单元格中有数据.

看起来UISearchDisplayControllers视图是一个通用视图,至少在segues和cell布局时...

我检查了从UISearchDisplayController到我的UITableViewController的所有连接,看起来都很好......

为什么SearchDisplayControllers视图不接受我的单元格布局和segue?

谢谢 :)

更新:刚刚弄清楚出了什么问题,但尚未找到解决方案.在我的cellForRowAtIndexPath中,当thr searchdisplayview在此方法中时,单元格始终配置为默认单元格.我是否真的需要在代码中创建我的单元格以使uisearchdisplay工作?为什么不能使用故事板中配置的单元格?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   (NSIndexPath *)indexPath
{
 static NSString *CellIdentifier = @"PersonCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    NSLog(@"Default Cell");
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

NSFetchedResultsController *controller = tableView == self.tableView ? self.fetchedResultsController : self.fetchedResultsControllerForSearch;

Person *p;
p = [controller objectAtIndexPath:indexPath];       

[(UILabel*) [cell viewWithTag:1] setText:p.name]; 
[(UILabel*) [cell viewWithTag:2] setText:@"Status"];    

if(p.avatarImage){
    UIImage *avatar = [[UIImage alloc] initWithData:p.avatarImage];
    [(UIImageView *) [cell viewWithTag:3] setImage:avatar];      
}

return cell;
Run Code Online (Sandbox Code Playgroud)

}

Jac*_*ald 12

问题是,当我在cellforrowatindexpath中获取单元格时,它没有从原始viewcontrollers tableview中获取它,所以我更改了

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
Run Code Online (Sandbox Code Playgroud)

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Run Code Online (Sandbox Code Playgroud)

现在一切都很好,细胞有故事板的布局,segues就像魅力一样.