presentModalViewController无法正常工作 [英] presentModalViewController not working
问题描述
这是我的代码:
ViewController *vc = [[ViewController alloc] initWithNibName:@"TableView" bundle:nil];
[self.navigationController presentModalViewController:vc animated:YES];
//[self setView:[vc view]];
如果我打电话,没有任何反应。但是,如果我将其更改为:
If I call it, nothing happens. However, if I change it to:
ViewController *vc = [[ViewController alloc] initWithNibName:@"TableView" bundle:nil];
//[self.navigationController presentModalViewController:vc animated:YES];
[self setView:[vc view]];
视图看起来很好(当然没有过渡)。
我做错了什么?初始化视图控制器时是否有任何特殊需要处理?我试图尽可能多地从Apple的例子中复制,但我不能让它工作......
The view appears just fine (without the transition, of course). What am I doing wrong? Is there anything special you have to take care of when initializing the view controller? I tried to copy as much as possible from Apple's examples, but I can't get this to work...
感谢您的任何输入!
- Ry
推荐答案
您只能从已经存在的控制器中呈现模态视图控制器屏幕上显示(通常通过UINavigationController或UITabBarController)。尝试创建一个UINavigationController,将viewController推送到它,然后然后呈现你的模态控制器。在Xcode中有一个初学者项目,它展示了如果你不熟悉它,如何创建一个基于UINavigationController的流程。
You can only present modal view controllers from controllers that have already been shown onscreen (usually through a UINavigationController or UITabBarController). Try creating a UINavigationController, pushing a viewController to it, and then presenting your modal controller. There's a starter project in Xcode that shows how to create a UINavigationController-based flow if you're unfamiliar with it.
还有一点要注意:如果你还没有将视图控制器推送到UINavigationController,.navigationController属性将为nil,并且它的消息将无效。
One other thing to note: if you haven't pushed the view controller onto a UINavigationController, the .navigationController property will be nil, and messaging it will have no effect.
这篇关于presentModalViewController无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!