I am implementing a search bar for my project. Part of the search is fine. I can display raw data and filter data with search text. When I click on a cell in the table of search results, it does not go to the detailed view. But for raw data, I can move on to a detailed view. I am using the prepareForSegue method as I am using the storyboard. Here is the code so far,
- (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]; } } }
When I tried to use the didSelectRowAtIndexPath method, I can move on to the detailed view. But I got an error message:
Here is the code for 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"); } }
Thanks for the help.
source share