Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
PETRA LUTZ
2,922 PointsTabBar and NavigationBar got hiden after adding pushViewController
I want to pass the variable " uid " between the FirstViewController and SecondViewController, so I used the following code to pass it. It successfully pass it, but the problem it hides the NavigationBar and the TabBar !
Any ideas on how I can solve it ?
SecondViewController *vc2 = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"]; vc2.uid = uid; [self.navigationController pushViewController:vc2 animated:YES];
9 Answers
Thomas Nilsen
14,957 PointsTry something like this:
UINavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
SecondViewController * vc2 = (SecondViewController *)navigationController.topViewController;
vc2.uid = uid;
[self.navigationController pushViewController:vc2 animated:YES];
PETRA LUTZ
2,922 PointsThe app crashes and says :
[SecondViewController topViewController]: unrecognized selector sent to instance 0x1f223250
Thomas Nilsen
14,957 PointstopViewController is the viewController that is visible in the navigation stack. Your storyboard might look a bit different than what I first thought. Would you mind taking a screenshot of the storyboard?
PETRA LUTZ
2,922 PointsHere is it : http://s29.postimg.org/afhfg3lp3/nin.png
Thomas Nilsen
14,957 Pointshmm - I don't see any reason why you navigationBar will disappear. Try adding this in SecondViewController:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
PETRA LUTZ
2,922 PointsStill, the same issue. In my case I am passing from LoginViewController (UIViewController) to FirstViewController(UITabBarController) [Please see picture again]. I think there is a problem of communication between these two.
Stone Preston
42,016 Pointsif you are using storyboards why not use a segue and implement prepare for segue to pass the variable?
PETRA LUTZ
2,922 PointsI tried to do that, but in that case the uid is not passed.
PETRA LUTZ
2,922 PointsI tried to do that, but in that case the uid is not passed.
Stone Preston
42,016 Pointscan you show me what you used? also is the viewcontroller you are trying to pass the variable to embedded in a navigation controller?
PETRA LUTZ
2,922 PointsI used this :
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"seg"]) { FirstViewController *vc2 = [segue destinationViewController]; vc2.uid = uid; } }
The FirstViewController is a login screen with, 2 fields (email, password) after receiving the success login from my jSON file, it gives success, with the uid the idea here is that I want to pass this uid inside the app to use it in other tab, so that It shows the content depending on the uid. The viewcontroller is embedded in a navigation controller.
Thomas Nilsen
14,957 Pointsif it's embedded in a navigation controller do this:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"seg"]) {
UINavigationController *navigationController = segue.destinationViewController;
FirstViewController *vc2 = (FirstViewController *)navigationController.topViewController;
vc2.uid = uid;
}
}
PETRA LUTZ
2,922 PointsPETRA LUTZ
2,922 PointsWhat is topViewController ?