xcode presentViewController 错误 - AppDelegate 没有可见的 @interface
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13066788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error with presentViewController - no visible @interface for AppDelegate
提问by Florian Ott
I am making a splitview application for ipad and I need to display a different view controller for login purposes. I call this in the didFinishLaunchingWithOptions function in Appdelegate:
我正在为 ipad 制作一个 splitview 应用程序,我需要为登录目的显示一个不同的视图控制器。我在 Appdelegate 的 didFinishLaunchingWithOptions 函数中调用它:
LoginViewController *login = [[LoginViewController alloc] init];
[info setModalTransitionStyle: UIModalTransitionStyleCrossDissolve];
[self presentViewController:login animated:YES completion: nil];
but I get the error "No visible @interface for AppDelegate declares the selector presentViewController" on the third line.
但我在第三行收到错误“AppDelegate 没有可见的@interface 声明选择器presentViewController”。
The view controller I want to display is set to the LoginViewController class. I have Imported all classes.
我要显示的视图控制器设置为 LoginViewController 类。我已经导入了所有课程。
I am pretty new to programming and would really appreciate any help!
我对编程很陌生,非常感谢任何帮助!
Thanks!!
谢谢!!
回答by sergio
What the error message says is that the class AppDelegate
does not contain a method called presentViewController
. Indeed, that method belongs to UIViewController
class.
错误消息说的是该类AppDelegate
不包含名为presentViewController
. 事实上,该方法属于UIViewController
类。
What you should do depends on how you created your project, whether it uses a navigation controller, a tab bar controller, or a simple view controller.
你应该做什么取决于你如何创建你的项目,它是使用导航控制器、标签栏控制器还是简单的视图控制器。
From your comment, I understand you used the Window-based template (or Empty application) to create your project. In this case, in your application:didFinishLaunching:
you should have something like this:
从您的评论中,我了解到您使用基于 Window 的模板(或 Empty 应用程序)来创建您的项目。在这种情况下,application:didFinishLaunching:
你应该有这样的东西:
self.login = [[LoginViewController alloc] init];
[self.window addSubview:self.login.view];
and also add to your AppDelegate.h the following declaration:
并将以下声明添加到您的 AppDelegate.h 中:
@property (nonatomic, strong) LoginViewController* login;
If this seems not to apply to your case, please, post your definition of application:didFinishLaunching:
如果这似乎不适用于您的情况,请发布您的定义 application:didFinishLaunching: