UISearchDisplayController - 为什么我的搜索结果视图包含空单元格? [英] UISearchDisplayController—why does my search result view contain empty cells?

查看:124
本文介绍了UISearchDisplayController - 为什么我的搜索结果视图包含空单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am about to go out of my mind here, in my Core Data databse I have a lot of users, i have hooked the database up to a tableviewcontroller via NSFetchedResultController, and when the view loads, I see all my users, and i can perform a push to a detail viewcontroller via storyboard segue... so far so god, my tableview contains a custom cell with an image view and 2 uitextlabels that all has their tag values assigned..

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

Now, when I perform the search I create a new NSFetchedResultController with a predicate, and performs the performFetch.. I then get the fetchedObjects property and it contains the users that match, so the search request is also working like a charm.. in all my tableviews datasources I check if self.tableView == self.searchdispl.view to see which controller I should query data from.. In all the controllers delegates I check to see which controller is active so i know which view to reload. If i nslog a lot of data it is all fine behind the scenes, the delegate and datasource methods all use the correct view and fetchcontroller..

在我的cellForRowAtIndexPath中我可以记录out我的user.name,这总是正确的,也是在搜索时。

In my cellForRowAtIndexPath i can log out my user.name, and that is always correct, also when searching.

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

The issue is that the UISearchDisplayController view that is on top only has empty cells, unless i set my UITableViewControllers dynamic prototype cell to basic, then both tableviews contain that label with the users name ! The segue from the cell still doesn't work, but there is data in the cell.

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

It seems as the UISearchDisplayControllers view is a generic view, at least when it comes to segues and cell layout...

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

I have checked all the connections from the UISearchDisplayController to my UITableViewController, and all looks fine...

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

Why will the SearchDisplayControllers view not accept my cell layout and segue ?

谢谢:)

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

Update : has just figured out what is going wrong, but not found the solution yet. In my cellForRowAtIndexPath the cell is always configured as the Default Cell when thr searchdisplayview is in this method.. Do i really need to create my cell in code for the uisearchdisplay to work ? Why can it not use the configured cell from the 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中获取单元格时,它没有从原始viewcontrollers tableview中获取它,所以我改变了行

The issue was that when i got the cell in cellforrowatindexpath, it didn't get it from the original viewcontrollers tableview, so i changed the line from

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

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

现在一切都很好,单元格具有故事板的布局,segues就像魅力一样......

and now all is good, the cell has the layout from storyboard and segues works like a charm..

这篇关于UISearchDisplayController - 为什么我的搜索结果视图包含空单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆