EDIT:
I just found: How to go from the result of a UISearchBarDisplayController to detailViewController
which I will look at!
I combine the “search bar and search display controller” with the underlying data obtained using the ResultsController using a storyboard. That is, I have to distinguish between:
if (self.tableView == self.searchDisplayController.searchResultsTableView) {
...
and the case when I just cited the results obtained from the data warehouse.
However, I am unable to get the correct line (pointer path) in the following case:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"StoreDetails"]) {
UINavigationController *navigationController = segue.destinationViewController;
StoreDetailsTableViewController *controller = (StoreDetailsTableViewController *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
Store *storeToDetail = nil;
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
NSLog(@"Row: %i", indexPath.row);
if (self.tableView == self.searchDisplayController.searchResultsTableView) {
storeToDetail = [self.filteredListContent objectAtIndex:indexPath.row];
} else {
storeToDetail = [self.fetchedResultsController objectAtIndexPath:indexPath];
}
controller.storeToDetail = storeToDetail;
}
}
which is called after:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString scope:@"All"];
...
with:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[self.filteredListContent removeAllObjects];
for (Store *store in [self.fetchedResultsController fetchedObjects])
{
if ([scope isEqualToString:@"All"] || [store.name isEqualToString:scope])
{
NSComparisonResult result = [store.name compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[self.filteredListContent addObject:store];
}
}
}
}
which is taken from the Apple TableSearch example.
The initial problem is twofold:
1) self.tableView is not like self.searchDisplayController.searchResultsTableView is ready to go
2) when searching indexPath (string) is always 0.
, didSelectRow... , , ... ?! , didSelectRow... , . , indexPath didSelectRow... , segue prepFor...:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Store *storeToDetail = nil;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
storeToDetail = [self.filteredListContent objectAtIndex:indexPath.row];
}
else
{
storeToDetail = [self.fetchedResultsController objectAtIndexPath:indexPath];
}
[self performSegueWithIdentifier:@"StoreDetails" sender:self];
}
. , , , .
!