I am working on an app whose main UI is based on a tab bar controller.
In one of the tabs I have a collection view, which drills down to a detail view via a navigation controller.
What I am trying to do is upon receipt of a push notification I would like to select this specific tab, fetch the latest data from the server, find the particular item to display, then push the detail view on to the screen to display said item.
My problem is I get the following message after collectionView:didSelectItemAtIndexPath:
Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'FavouriteItem'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
Here is what I am doing so far:
App Delegate application:didReceiveRemoteNotification:
[self selectFavouritesTab];
NHFavouritesViewController *favouritesViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Favourites"];
[favouritesViewController displayFavouriteForPushNotificationWithId:favouriteId];
From FavouritesViewController - After fetching the latest favourites, I send a message to displayFavouriteItemWithId:
- (void)displayFavouriteItemWithFavouriteId:(NSNumber*)favouriteId
{
NSArray* results = [_collectionViewData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF.favouriteId == %@", favouriteId]];
NSInteger row = [_collectionViewData indexOfObject:[results lastObject]];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
[[self collectionView] selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
[self.collectionView.delegate collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
[self performSegueWithIdentifier:@"FavouriteItem" sender:self];
}
And it is at this point it crashes. I understand what the crash message is saying, however what I don't know is how to place NHFavouritesViewController inside a navigation controller (which is embedded inside one in the storyboard) when I respond to the push notification in the app delegate?