我正在實施我的項目的搜索欄。搜索部分沒問題。我可以顯示原始數據並使用搜索文本過濾數據。當我點擊搜索結果tableView的單元格時,它不會轉換到詳細視圖。但對於原始數據,我可以轉換到詳細視圖。我使用prepareForSegue
方法,因爲我使用的是故事板。 下面的代碼到目前爲止,搜索欄與prepareForSegue DetailViewController
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString: @"Book Detail Segue"]) {
BookDetailsTVC *bookDetailsTVC = segue.destinationViewController; // for the detail view controller
bookDetailsTVC.delegate = self;
if (self.tableView == self.searchDisplayController.searchResultsTableView) { // The if block is not working
NSLog(@"Search Display Controller");
bookDetailsTVC.book = [self.searchResults objectAtIndex: self.searchDisplayController.searchResultsTableView.indexPathForSelectedRow.row];
} else {
NSLog(@"Default Display Controller");
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
bookDetailsTVC.book = [self.objects objectAtIndex: indexPath.row];
}
}
}
當我嘗試使用didSelectRowAtIndexPath
方法,我可以過渡到詳細視圖。但是我有這樣的錯誤消息:
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
Unbalanced calls to begin/end appearance transitions for <BookDetailsTVC: 0x69b5300>.
下面是didSelectRowAtIndexPath方法的代碼:
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath
{
BookDetailsTVC *bookDetailsTVC = [[BookDetailsTVC alloc] init];
if (tableView == self.searchDisplayController.searchResultsTableView) {
bookDetailsTVC.book = [self.searchResults objectAtIndex: self.searchDisplayController.searchResultsTableView.indexPathForSelectedRow.row];
[self performSegueWithIdentifier: @"Book Detail Segue" sender:self];
NSLog(@"Search Display Controller");
} else {
bookDetailsTVC.book = [self.objects objectAtIndex: indexPath.row];
[self performSegueWithIdentifier: @"Book Detail Segue" sender: self];
NSLog(@"Default Display Controller");
}
}
感謝您的幫助。
這也給我修好了!我一直在嘗試爲我的第一個應用解決這個難以解決的問題,現在一週左右!感謝分享。 – 2013-06-03 07:30:23
'self.searchDisplayController.active'部分保存了我的夜晚!非常感謝你。我正在學習本教程,無法使其工作:http://www.raywenderlich.com/16873/how-to-add-search-into-a-table-view您的解決方案解決了我的問題。 – scaryguy 2013-12-31 23:55:38
謝謝!在我的情況下,問題是使用self.tableView而不是self.searchDisplayController.searchResultsTableView。 – Borzh 2014-10-05 20:30:20