I have a UITabViewController that is responsible for managing multiple views (and navigation controllers). The views were connected in Storyboard by Ctrl clicking the UITabViewController and selecting "relationship segue" to the other views.
Problem is, the prepareForSegue is not firing at all in the UITabViewController. Nothing else was touched in code. NSLog does not output upon switching views by clicking on the tab bar.
CustomTabViewController.m
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
NSLog(@"Here..");
NSLog(@"%@", [segue destinationViewController]);
}
Does anyone know why this is happening? Thanks
Assuming that you meant UITabBarController
instead of UITabViewController
, clicking on a UITabBarItem
to switch views will not fire prepareForSegue:sender:
. However, it will cause tabBarController:didSelectViewController:
to fire in your UITabBarControllerDelegate
, so you can use that to perform any actions you wished to perform in prepareForSegue:sender:
. If you want to reference the view controller that you're navigating to, instead of [segue destinationViewController]
, you can just reference the viewController
parameter directly.
Tab bar controllers (UITabBarController objects) do not segue to the view controllers that are contained in their tabs.
As far as I know there is no such thing as a UITabViewController. It pays to use the correct class names when posting a question. At first I misread your question, and thought it said "UITableViewController".(So did @MatteoGobbi, it seems)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With