I have three controllers (FriendVC, ChatVC, PrivateChatVC) inside storyboad, and navigation is sequential :
A user can navigate from FriendVC
to ChatVC
(in TabBarController
), and then to PrivateChatVC
.
Now, I need to make some button that will open PrivateChatVC
from FriendVC
but will also put ChatVC
on navigation stack, so when a user will press back from PrivateChatVC
he will be returned to ChatVC
.
Problem I'm facing is that my ChatVC
is a TabBarController
.
Below is the code I'm trying:
[self.tabBarController setSelectedIndex:1];
PrivateChatController * privateChatController = [self.storyboard instantiateViewControllerWithIdentifier:@"privatechat"];
[self.navigationController pushViewController:privateChatController animated:YES];
I'm assuming that [self.tabBarController setSelectedIndex:1]
will load the tabbar and then [self.navigationController pushViewController:privateChatController animated:YES];
will load PrivateChatVC
.
However, it only takes me to ChatVC
and PrivateChatVC
never loads.
You're on the right track, you need to select the ChatVC tab as you've done, but use a singleton class and set a param so that when ChatVC becomes the active VC it knows to immediately push PrivateChatVC.
In FriendVC:
_singleton.showPrivateChat = YES;
[self.tabBarController setSelectedIndex:1]; // select ChatVC tab
In ChatVC:
- (void) viewDidAppear {
if (_singleton.showPrivateChat) {
PrivateChatController * privateChatController = [self.storyboard instantiateViewControllerWithIdentifier:@"privatechat"];
[self.navigationController pushViewController:privateChatController animated:YES];
_singleton.showPrivateChat = NO; // reset boolean
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments