0

I have an app which has a sidebar menu (a UITableView) with different rows that are connected separately with the main view controller with a (push) Segue.

Only one of this doesn't work, so when I tap on it I recieve this message:

**** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainTabBarController topViewController]: unrecognized selector sent to instance 0x14880ce00'terminating with uncaught exception of type NSException*

In the SideBarViewController this is the part of the code that causes the crash:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(@"[segue identifier]: %@",[segue identifier]);

if ([[segue identifier] isEqualToString:@"sync"]) {
    MainViewController *mainViewSync= (MainViewController *)[[segue destinationViewController] topViewController];
    mainViewSync.sync = 1;
}}

How can I fix That?

  • 1
    `topViewController` is a `UINavigationController` property, not a `UITabBarController` one. Since I guess that `MainTabBarController` is a `UITabBarController`, that's why you get a crash, since `[segue destinationViewController]` is a `MainTabBarController` and not as you think a `MainViewController`. – Larme Sep 06 '21 at 08:41
  • @Larme thank you. Is there a corresponding property for a TabBarViewController? How do I connect them? – Fabrizio L. Sep 06 '21 at 08:46
  • You need to understand what means `topViewController`, see https://stackoverflow.com/questions/33395463/in-uinavigationcontroller-what-is-the-difference-between-topviewcontroller-visi Now, your `UITabBarController`, does it have a `UINavigationController` on one of its tab? You want to know which tab is currently selected? And if that's the case, you want to know if there is a modally presented one? The last pushed one through a UINavigationController? It's lacking informations on your architecture... – Larme Sep 07 '21 at 07:35

0 Answers0