在 appdelegate.m 文件中找不到 viewcontroller

发布于 2024-12-12 01:17:52 字数 803 浏览 0 评论 0原文

我正在按照 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑,眼淚并存 2024-12-19 01:17:52

您是否在标头中声明了 UIViewController 类型的 viewController 并进行了合成?看起来您正在 AppDelegate 中工作,我建议不要这样做。您应该在 viewcontrollers 的 viewDidLoad:viewWillAppear: 方法中实现此功能。

Have you declared viewController of type UIViewController in your header, and synthesized? It also looks like you are doing work in your AppDelegate which I would advise against. You should implement this in your viewcontrollers' viewDidLoad: or viewWillAppear: methods.

长伴 2024-12-19 01:17:52

我也遇到了同样的问题,我相信我知道如何解决它。我相信您使用故事板创建了测试项目?当您使用故事板创建项目时,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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文