Interchanging presentModalViewController and pushViewController

走远了吗. 提交于 2019-12-11 20:36:26

问题


I am using a sample ViewController that is displayed in the sample program as a presentModalViewController. However, I want to use pushViewController on the UIViewController instead. The problem is that when I switch to pushViewController, the ViewController no displays properly. Functions in the ViewController are called, but I don't see anything. I change back to presentModalViewController and everything works.

The question is what do I need to do to make pushViewController work?

FCVC *fcVC;  
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"fcVC" 
                                               owner:self     
                                             options:nil];  
fcVC = [array objectAtIndex:0];  

A. [self presentModalViewController:fcVC animated:YES]; // "WORKS"
or
B. [self.navigationController pushViewController:fcVC animated:YES]; // "Doesn't work


回答1:


Do you have a UINavigationController actually set up? "self" should be a viewController that is loaded inside UINavigationController.




回答2:


To create a NavigationController in a view-based application you have to set the NavigationController in the delegate class.

Like This

In delegate .h class

  MyViewController *viewController;

In delegate .m class

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

UINavigationController *nvcontrol =[[UINavigationController alloc] initWithRootViewController:viewController];

[window addSubview:nvcontrol.view];

[window makeKeyAndVisible];

}

Here "MyViewController" should be replaced by your viewcontroller.

All The Best.



来源:https://stackoverflow.com/questions/2569928/interchanging-presentmodalviewcontroller-and-pushviewcontroller

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