Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
1
i use navigationController in the application that i develop. At a certain point i push a new controller to stack but i cant see it in navigation controller's controllers list but the new pushed view controller can be seen in the screen. Why navigation controller's stack return wrong array ?
Here my code is
Code:
    self.mainNC = [DELEGATE.grabStoryboard instantiateViewControllerWithIdentifier:@"giveAdNC"];
   
    if (![Fucntions readPlistFile]) {
       
        [self.mainNC pushViewController:[DELEGATE.grabStoryboard instantiateViewControllerWithIdentifier:@"signInVC"] animated:YES];

NSLog(@"TOP VIEW CONTROLLER %@", self.mainNC.viewControllers);
}

SignInVc is the view controller class that i push and can be seen in screen but not in navigation controller's stack.
 
You need to tell your UINavigationController to push.

Try this. [self.navigationController pushViewController:self.mainNC animated:YES];
 
@dookie pretty much has it, but I wanted to clear something up in case it wasn't obvious:

Code:
self.mainNC = [DELEGATE.grabStoryboard instantiateViewControllerWithIdentifier:@"giveAdNC"];

When you are calling instantiateViewControllerWithIdentifier, you are not fetching the existing instance of your current Navigation Controller, instead you are creating an entirely new instance of it and attempting to push your view into that.

See the notes for instantiateViewControllerWithIdentifier (emphasis mine):
You use this method to create view controller objects that you want to manipulate and present programmatically in your application. [...] This method creates a new instance of the specified view controller each time you call it.
 
I recommend you use segue's to push view controllers. That will fix the bug Mascots mentions and should make your code cleaner.
 
I recommend you use segue's to push view controllers. That will fix the bug Mascots mentions and should make your code cleaner.
This works for some simple things, but I feel that there is less and more straight forward code when using the pushNavigationController method. Everything can be accomplished in one method rather than two, that is if you need to pass data to the next viewController. No need for the prepareForSegue method at all.
 
I use both depending on circumstance.

I enjoy having a nicely connected Storyboard because that eliminates a lot of senseless logic and gives an overview of an apps frame, but other times I'll just peg storyboard for an instance and pass it myself, like when I build smaller view components that lack presence in SB or a reusable base.

Or I can't get Storyboard to load not in XML format.
 
I believe the problem here is that when you initialize a UIViewController by identify you only get the instance of that view controller and not the UINavigationController it is embedded in. To solve your problem you will need to instantiate and present the Navigation Controller (which embeds the CameraViewController). Although there are many ways to do this..
 
Thanks for answers guys. Still i am in trouble with the same problem. I try this one at last.
Code:
UINavigationController *denemeNC = [self.storyboard instantiateViewControllerWithIdentifier:@"profilimNC"];
           
SignInViewController *signInVC = [self.storyboard instantiateViewControllerWithIdentifier:@"signInVC"];
           
[denemeNC pushViewController:signInVC animated:YES];
and then present the navigation controller. But still same problem. SignInViewController can be seen on screen but when i write down its viewControllers then signInVc is not there
 
Are you pushing a view into the current navigation stack, or are you attempting to show a new navigation controller that you can then present over your current one?
Your code and descriptions are contradictory, so it's unclear what your goal is.

If it's the former, you should be maintaining a reference or grabbing a reference to the current nav stack from the VC doing the work (not instantiating a new nav stack from Storyboard), and then push a newly instantiated sign-in VC through that existing reference.

If it is the latter, you can either instantiate a _new_ navigation stack from Storyboard that already has the Sign-in VC as the root view controller (so you don't have to call the
sign-in VC), and then present the navigation controller modally...
OR instantiate your sign-in VC, manually create a new Navigation stack while setting the sign-I'm VC as the top view controller, and then present that newly created navigation stack.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.