我在這裏想到了,在我的Core Data數據庫中,我有很多用戶,我通過NSFetchedResultController將數據庫連接到tableviewcontroller,當視圖加載時,我看到所有用戶,並且我可以通過storyboard segue執行一個詳細視圖控制器的推...迄今爲止,上帝,我的tableview包含一個圖像視圖的自定義單元格和2個uitextlabels,所有都有他們的標籤值分配..UISearchDisplayController - 爲什麼我的搜索結果視圖包含空單元格?
現在,當我執行搜索我用一個謂詞創建一個新的NSFetchedResultController,並執行performFetch ..然後我得到了fetchedObjects屬性,它包含匹配的用戶,所以搜索請求也像魅力一樣工作..在我所有的tableviews數據源中檢查是否self.tableView == self.searchdispl.view查看哪些控制器我應該查詢數據..在所有co ntrollers代表我查看哪個控制器是活動的,所以我知道要重新加載哪個視圖。如果我記錄了大量的數據,它在後臺都很好,代理和數據源方法都使用正確的視圖和fetchcontroller ..
在我的cellForRowAtIndexPath我可以註銷我的user.name,並且始終是正確的,也在搜索時。
問題是,頂部的UISearchDisplayController視圖只有空單元格,除非我將我的UITableViewControllers動態原型單元格設置爲基本,然後這兩個tableviews都包含帶有用戶名稱的標籤!細胞中的細胞仍不起作用,但細胞中有數據。
這似乎爲UISearchDisplayControllers視圖是一個通用的觀點,至少當它涉及到塞格斯和單元佈局...
我檢查了我的UITableViewController從UISearchDisplayController所有的連接,所有看起來很好。 ..
爲什麼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;
}
好吧,我只是讓這個坐在這裏,即使我只是想出了什麼是錯的,我有點尷尬,但也許這篇文章可以幫助別人:)問題是,當我得到在cellforrowatindexpath中的單元格,它沒有從原始viewcontrollers tableview中獲取它,所以我改變了從UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];到UITableViewCell * cell = [self。tableView dequeueReusableCellWithIdentifier:CellIdentifier];現在一切都很好,單元格有故事板和插件的佈局,就像一個魅力:) – 2012-02-29 11:38:33
這真的起作用了,你應該發佈這個作爲你自己問題的答案! – 2013-12-06 11:04:40