How can I display a view controller modally, using the parent's navigation controller?

不问归期 提交于 2019-12-25 01:45:49

问题


I'm implementing a UITabBar in the middle of my navigation stack without UITabBarController. The UITabBar is in the DetailViewController which delegate a portion of the screen to the view controller associated with the selected tab element. Inside one of view controller's thats displayed via tab bar selection, there's a UIButton which needs to display a view modally. I tried [self presentModalViewController:modalNavController animated:YES];, but the new navigation bar was hidden underneath the nav bar of the parent controller, DetailViewController. So what I think I need to do is use the parent's navigation controller to present the view modally so that the new nav bar is ON TOP of the DetailViewController nav bar.

I know its possible because I have an ad in the DetailViewController, and tapping the add gives me the desired result, but I haven't been able to incorporate that code. I could also probably display the UIButton from the DetailViewController rather than the subView, but I need to use this pattern a few times, so I'd rather not have to work with an unorthodox hack like that.

THANKS!

EDIT

I have already tried adding the new view to a navigation controller and then presenting the navigation controller like so:

WriteReviewController *newReview = [[WriteReviewController alloc] initWithNibName:@"WriteReviewController" bundle:nil];
UINavigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:newReview];
// This is intended to be presented in another view controller class
modalNavController.navigationBar.barStyle = UIBarStyleDefault;  
[self.parentViewController presentModalViewController:modalNavController animated:YES]; 
[modalNavController release];

回答1:


Is self subclassing UIViewController or something else? I have successfully done a view with a nav controller this way although I don't usually do it with a nib. See if you have success with pushing the view first and then try to presentModalView.

Also I recommend using the delegate method of implementing this. Although not necessary for what you are doing you will find you will run into less problems later and is probably considered the "correct" way of doing things.



来源:https://stackoverflow.com/questions/3765158/how-can-i-display-a-view-controller-modally-using-the-parents-navigation-contr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!