iphone - UISearchDisplayController—为什么我的搜索结果 View 包含空单元格?

标签 iphone nsfetchedresultscontroller uisearchdisplaycontroller

我快要疯了,在我的核心数据数据库中,我有很多用户,我已经通过 NSFetchedResultController 将数据库连接到 tableviewcontroller,当 View 加载时,我看到了所有用户,我可以通过 Storyboard Segue 执行对详细 View Controller 的推送...到目前为止,上帝,我的 tableview 包含一个带有 ImageView 的自定义单元格和 2 个 uitextlabels,它们都分配了标签值..

现在,当我执行搜索时,我使用谓词创建一个新的 NSFetchedResultController,并执行 PerformFetch.. 然后我获取 fetchedObjects 属性,它包含匹配的用户,因此搜索请求也像魅力一样工作。 .在我的所有 TableView 数据源中,我检查 self.tableView == self.searchdispl.view 是否应该从哪个 Controller 查询数据。.在所有 Controller 委托(delegate)中,我检查哪个 Controller 处于事件状态,以便我知道要重新加载哪个 View 。如果我记录大量数据,那么在幕后一切都很好,委托(delegate)和数据源方法都使用正确的 View 和获取 Controller ..

在我的 cellForRowAtIndexPath 中,我可以注销我的用户名,这始终是正确的,搜索时也是如此。

问题是顶部的 UISearchDisplayController View 只有空单元格,除非我将 UITableViewControllers 动态原型(prototype)单元格设置为基本,然后两个 TableView 都包含带有用户名的标签!单元格的转接仍然不起作用,但单元格中有数据。

看起来 UISearchDisplayControllers View 是一个通用 View ,至少在 Segues 和单元格布局方面......

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

为什么 SearchDisplayControllers View 不接受我的单元格布局和转场?

谢谢:)

更新:刚刚找出问题所在,但尚未找到解决方案。 在我的 cellForRowAtIndexPath 中,当 thr searchdisplayview 处于此方法中时,单元格始终配置为默认单元格。我真的需要在代码中创建单元格才能使 uisearchdisplay 工作吗?为什么它不能使用 Storyboard 中配置的单元格?

- (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;

}

最佳答案

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

现在一切都很好,单元格具有 Storyboard的布局,并且 segues 工作起来就像一个魅力..

关于iphone - UISearchDisplayController—为什么我的搜索结果 View 包含空单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9497860/

相关文章:

iphone - 将图像加载到一个单元格 UITableView - xcode

ios - UITableView 和 NSFetchedResultsController 内存泄漏

ios - CoreData 保存问题

ios - NSFetchedResultsController 不使用合并的上下文更新缓存

ios - UISearchDisplayController 中的自定义 UITableViewCell

ios UISearchDisplayController在滚动结果 TableView 时关闭

ios - tableView.tableHeaderView = UISearchDisplayController.searchBar;并调用 setContentInset : ; searchBar is not drawn when i scroll the table

iPhone - 将 mp3 转换为 wav?

iphone - 内置保存按钮文本

iphone - 在 iphone safari webapp 中隐藏键盘