This is the hierarchy of my app
- There is a TabBarViewCOnyroller with 4 tabs
- Each tab shows a TableListViewOCnroller
- When user selects a row in the the TableListViewCOntrilelrs, different view controllers are pushed depending on which tab and which row. Each of these has a navigate back button to that will take the UI back to Tab-Bar view controller
For e.g. Chat tab displays a list of chats in timestamp sorted order. The last chat in the exchange with each far-end is shown. When user selects a certain row, it goes it into a view controller that shows all the messages between user and far-end who is connected with the row.
When I get a push notification with a message from a particular far-end, and user selects it, I want the app to directly shift to the view controller with all the messages with the far-end with a navigate back button pointing to the "Chat tab". I know how to show the message display view controller programmatically, but I don't know how to embed it in a way that will allow user to navigate back to the chat tab.
Can someone point me to some example code on how this can be achieved. Sorry to be asking for a ready-made solution. Too much base-framework stuff to master, so no time to master UI stuff!
EDIT with code I am using
NSInteger index = 1 ;// the index of the chat tab
UITabBarController *myTabBarController = (UITabBarController *)self.window.rootViewController;
myTabBarController.selectedIndex = index;
UINavigationController *navVC = myTabBarController.viewControllers[index];
ChatListTableViewController *listVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"chatlistview"];
listVC.navigationItem.backBarButtonItem.title = @"Chats";
MessageDisplayViewController *detailVC = [[MessageDisplayViewController alloc] init];
//Initialize all the variables needed by JSQMessage class
detailVC.hidesBottomBarWhenPushed = YES;
detailVC.title = detailVC.recipient = userInfo[@"sender"];
//To Do Map farEndID to farEndNickName using unique user table
detailVC.recipientNickName= detailVC.recipient ;
detailVC.managedObjectContext=self.managedObjectContext ;
detailVC.senderDisplayName=[[NSUserDefaults standardUserDefaults] stringForKey:@"NickName"];
detailVC.senderId=[[NSUserDefaults standardUserDefaults] stringForKey:@"UserID"];
//navVC.viewControllers = @[listVC, detailVC];
navVC.viewControllers = @[listVC];
[navVC pushViewController: detailVC animated:NO];