在 appdelegate.m 文件中找不到 viewcontroller
我正在按照 ios 教程将 Facebook 合并到我的应用程序中。一切都很顺利,直到我到达有关添加注销按钮的部分。我不断收到错误消息,指出在类型对象上找不到属性“ViewController”。我做错了什么?这是我的 appdelegate.m 文件中的代码。
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Add the requests dialog button
UIButton *requestDialogButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
requestDialogButton.frame = CGRectMake(40, 150, 200, 40);
[requestDialogButton setTitle:@"Send Request" forState:UIControlStateNormal];
[requestDialogButton addTarget:self
action:@selector(requestDialogButtonClicked)
forControlEvents:UIControlEventTouchUpInside];
[self.viewController.view addSubview:requestDialogButton];
// ...
}
I am following the ios tutorial to incorporate Facebook into my app. Everything went fine until I got to the part about adding a logout button. I keep getting an error stating property "ViewController" not found on object of type. What am I doing wrong? Here is the code from my appdelegate.m file.
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Add the requests dialog button
UIButton *requestDialogButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
requestDialogButton.frame = CGRectMake(40, 150, 200, 40);
[requestDialogButton setTitle:@"Send Request" forState:UIControlStateNormal];
[requestDialogButton addTarget:self
action:@selector(requestDialogButtonClicked)
forControlEvents:UIControlEventTouchUpInside];
[self.viewController.view addSubview:requestDialogButton];
// ...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否在标头中声明了
UIViewController
类型的viewController
并进行了合成?看起来您正在AppDelegate
中工作,我建议不要这样做。您应该在viewcontrollers 的 viewDidLoad:
或viewWillAppear:
方法中实现此功能。Have you declared
viewController
of typeUIViewController
in your header, and synthesized? It also looks like you are doing work in yourAppDelegate
which I would advise against. You should implement this in yourviewcontrollers' viewDidLoad:
orviewWillAppear:
methods.我也遇到了同样的问题,我相信我知道如何解决它。我相信您使用故事板创建了测试项目?当您使用故事板创建项目时,appDelegate 不包含 viewController...因为故事板将处理该问题。
重新创建项目并取消选中 StoryBoard 复选框...还有自动引用计数...
问候,
埃兹弗拉格
I'm also having the same issue, and I believe I know how to fix it. I believe that you created your test project with a storyboard? When you create a project with a storyboard, the appDelegate doesn't contain a viewController... as the storyboard will handle that.
Recreate the project and uncheck the StoryBoard check box... also the Automatic Reference Counting...
Regards,
Ezfrag