Claud
Claud

Reputation: 1075

Segue data from VC to TabBar to VC (iOS)

I have a project with storyboard that I changed recently.

Before it was VC -> VC1 -> VC2 and was using this code to segue data between the ViewControllers

if([segue.identified isEqualToString:@"SegueData"]){
   StoreViewController *svc = [segue destinationViewController];
   NSIndexPath *path = [allStoresTable indexPathForSelectedRow];
   Stores *s = [stores objectAtIndex:path.row];
   [svc setCurrentStores:s];
}

Now I need to pass that data from VC -> TabBar -> VC1, VC2

How can I do that now?

I've tried this code from here that is similar to my problem (http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=2884) but app crashed when running.

UITabBarController *tabBarController = segue.destinationController;

UINavigationController *navController1 = [tabBarController.viewControllers objectAtIndex:0];
StoreViewController *svc= navController1.topViewController;
NSIndexPath *path = [allStoresTable indexPathForSelectedRow];
Stores *s = [stores objectAtIndex:path.row];
[svc setCurrentStores:s];

Also this line is causing the crash

StoreViewController *svc= navController1.topViewController;

gives me the warning "Incompatible pointer types initializing 'StoreViewController * _strong' with an expression of type 'UIViewController*'

Upvotes: 0

Views: 789

Answers (1)

rdelmar
rdelmar

Reputation: 104092

Ok, your problem is the line, because there is no navigation controller at index 0, that's where your StoreViewController is:

UINavigationController *navController1 = [tabBarController.viewControllers objectAtIndex:0];

Just change that line to:

StoreViewController *scv = [tabBarController.viewControllers objectAtIndex:0];

And delete the line that starts StoreViewController = *svc ....

Upvotes: 2

Related Questions