user998840
user998840

Reputation: 11

iPhone - change navigation controller's view, using a button in a subview

I have a navigation controller with a rootview. The rootview contains buttons, which push new views onto the navigation controller correctly.

However, on this rootview, I also have subview (it's a scrolling preview like the appStore images, view made of 3 UIview items). On these UIViews, there is a button which I'd like to change the rootview navigation controller, like the other buttons.

At the moment, it builds and runs, but the new view is not pushed. Any ideas?

Click method on on the ScrollItem button:

MyViewController *newView = [[MyViewController alloc] initWithNibName:@"ManageMyPain" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];  

... i guess it is because, self doesn't have a navigation controller, but the rootview does.

Thanks!!

Upvotes: 0

Views: 816

Answers (2)

Nekto
Nekto

Reputation: 17877

Yes, it is because self.navigationController will be nil if you didn't push that controller on navigations stack or if you didn't set it manually.

So you just need to have reference to rootViewController.navigationController and then [navigationController pushViewController:newView animated:YES]; will work perfectly.

Upvotes: 0

Or Ron
Or Ron

Reputation: 2343

The property "navigationController" is only being set in a view controller if he's pushed to the navigation controllers stack. your second view is a sub view of a push viewcontroller which means this property is NULL and will not do anything if you try pushing things to it.

Upvotes: 1

Related Questions