如何在present出来的viewcontroller里使用push方法
如何在present出来的viewcontroller里使用push方法?
这个一搜就有代码,我为什么继续写呢?很简单,我碰到了这个问题,写下来。以后忘记了就在我自己的博客里面看。
我们弹出present 就是这样的,看代码:
RegistViewController *vc = [[RegistViewController alloc] initWithNibName:@"RegistViewController" bundle:nil];
[self presentViewController:vc animated:YES completion:nil];
但是!要在RegistViewController 中进行PUSH,那是行不通的!
改变后的代码:
RegistViewController *vc = [[RegistViewController alloc] initWithNibName:@"RegistViewController" bundle:nil];
//加上一个底部UIviewController设置为根视图
UIViewController * controller = self.view.window.rootViewController;
//说实话下面的两句代码,我不懂这里有什么意思,有知道的大神麻烦留言,感激不尽
controller.modalPresentationStyle = UIModalPresentationCurrentContext;
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//创建一个导航UINavigationController
UINavigationController * YMNavigationController = [[UINavigationController alloc] initWithRootViewController:vc];
//隐藏导航栏--我们present出来的ViewController一般是不需要导航栏的,如果需要可以注释下面的代码
YMNavigationController.navigationBarHidden = YES;
//改后的代码 这样就可以push了 注意:这里present的参数不是原先的ViewController了,是NavigationController!!
[self presentViewController:YMNavigationController animated:YES completion:nil];
至此,没问题了!大功告成,欢迎大家留言!
浙公网安备 33010602011771号