presentModalViewController 不工作 [英] presentModalViewController not working

查看:21
本文介绍了presentModalViewController 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

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

感谢您的任何意见!

-- 赖

推荐答案

您只能从已经在屏幕上显示的控制器(通常通过 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆