プロジェクトの検索バーを実装しています。検索部分は大丈夫です。生データを表示し、検索テキストでデータをフィルタリングできます。検索結果のtableViewのセルをタップしても詳細ビューに遷移しませんでした。しかし、生データについては、詳細ビューに移行できます。ストーリーボードを使用しているので、このprepareForSegue
方法を使用します。これまでのコードは次のとおりです。
- (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");
}
}
手伝ってくれてありがとう。