I’m using storyboard and XCode 4.3 to create an app that has a tab bar as root view. Even though my app has other segues that work just fine, one of them just does not trigger. It’s supposed to trigger when the third item of the tab is selected. The only thing I can see is that the tab bar actually loads the new view, but no information is passed.
The connections on Storyboard are as follow : Root View controller (Tab bar) -> Navigation Controller -> CapitolDetailViewController (which has a push segue from another view controller)
I’ve tried many changes in the connections, code, etc. But it just doesn’t trigger this segue. I tried to change the code in my AppDelegate to add the new controllers that were missing. The code for my applicationDidFinishLaunching is the following:
NSManagedObjectContext *context = [self managedObjectContext];
NSError *error;
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *view1 = [[tabBarController viewControllers] objectAtIndex:0];
UINavigationController *view2 = [[tabBarController viewControllers] objectAtIndex:1];
UINavigationController *view3 = [[tabBarController viewControllers] objectAtIndex:2];
SCDMasterViewController *view11 = [[view1 viewControllers] objectAtIndex:0];
view11.managedObjectContext = self.managedObjectContext;
SerieDetailViewController *view22 = [[view2 viewControllers] objectAtIndex:0];
CapitolDetailViewController *view33 = [[view3 viewControllers] objectAtIndex:0];
return YES;
Where “SerieDetailViewController” is the one that should pass the information when the 3rd item is selected, and “CapitolDetailViewController” is the one that should receive it.
Code for my segue: (it doesn’t even enter the segue, de NSLOG never shows up)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(@"Entra segue");
if ([segue.identifier isEqualToString:@"mostraCapitol"]) {
NSString *nom = @"";
nom= serieName;
CapitolDetailViewController *destViewController = segue.destinationViewController;
destViewController.serieName2 = nom;
}
}
Anyone knows what is wrong?
UPDATE: even though I received an answer that helped me to correct some compilation errors, the problem is still there. If I click the tab bar item, it loads an empty view. It never calls the segue. It looks like the tab bar items and the view controllers are not attached.
Try checking the segue method that does not work. Make sure your identifier for the segue in the storyboard mach the one in your class. From the look of your code and all the comments it seems that your code is fine and should work. The only place that might give you an issue would be different identifiers for the segue in storyboard. I hope this resolves your issue my friend.
Edit:
well i don’t know if this works for you but i have a different approach in setting up the core data in tab bar app. in .h file of the delegate almost everything is generic, in .m particularly
applicationdidfinishwithoptioni use index number in order to sort the views in view controller that i add to tab bar. i hope this helps, here is the code i use.by using index numbers i was able to achieve the same scenario without any error and for the start up view i used a child that i plugged in as initial modal view. hope this helps you. in my case core data was to be added to multiple tabs, i do not know if you have the same need.
EDIT 1
here is my
Appdelegate.hand here is the
app delegate.mnow bare in mind that i use both classes for for data entities and declared the managed objects in both classes. one thing is for sure when using core data your initial view has to have the managed objects. if this does not help you then i sugest you can take a look at tim roadley’s core data tutorial or paul hagurty’s stanford core data class. if you need a whole project to look at let me know and ill try to get something together and place a link so you can download it, but i believe if you have created a proper model and are using the right methods in app delegate similar to what i did, it should work. hope this helps you my friend.