简体   繁体   中英

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!!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM