要么调用AppDelgate要么调用ViewController [英] Either AppDelgate is called or ViewController is

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

问题描述

我希望在启动时同时我的AppDelegate和ViewController.

I am wanting both my AppDelegate and my ViewController to be called on startup (as expected).

仅调用ViewController时:

When only the ViewController is called:

int main(int argc, const char * argv[]) {
    return NSApplicationMain(argc, argv);
}

当调用AppDelegate而未调用视图控制器时.

When the AppDelegate is called and the view controller is not.

#import "AppDelegate.h"

int main(int argc, const char *argv[])
{
    NSArray *tl;
    NSApplication *application = [NSApplication sharedApplication];
    [[NSBundle mainBundle] loadNibNamed:@"ViewController" owner:application topLevelObjects:&tl];
    
    AppDelegate *applicationDelegate = [[AppDelegate alloc] init];      // Instantiate App  delegate
    [application setDelegate:applicationDelegate];                      // Assign delegate to the NSApplication
    [application run];                                                  // Call the Apps Run method
    
    return 0;       // App Never gets here.
}

我认为我的问题是 main.c 的第二次尝试是...

I think my problem is that with the second attempt of the main.c is that...

NSApplication *application = [NSApplication sharedApplication];
        [[NSBundle mainBundle] loadNibNamed:@"ViewController" owner:application topLevelObjects:&tl];

不能按预期工作.我在IB中实际在哪里设置"Nib"?

is not working as expected. Where do I actually set the 'Nib' in the IB?

怎么了?

推荐答案

您有这种困惑....您应该在这里仔细查看我的其他答案:

You've got this kind of confused.... you should look more closely at my other answer over here: Other Answer

您的第一个main.c示例完全错误.您的第二个main.c与我提供的示例更接近,但更好,但是您正在调用 viewController ,就像我的示例一样,您应该在其中引用MainMenu笔尖.

Your first main.c example is completely wrong. Your second main.c, which is closer to the example I gave is better, but you're calling viewController where you should be referencing the MainMenu nib, as in my example.

此行是错误的:

 [[NSBundle mainBundle] loadNibNamed:@"ViewController" owner:application topLevelObjects:&tl];

在那里输入NIB名称...这就是为什么方法参数称为"loadNibNamed":)-并摆脱@"ViewController"的原因.

put the NIB name there... that's why the method argument is called "loadNibNamed" :)- and get rid of @"ViewController".

现在,如果您想调用一个完整的笔尖,那么您就不需要我的例子了.那是为真正想要几乎完全采用程序设计的人设计的.

Now if you are trying to call a full blown nib, then you don't really need my example. That was designed for people who are really trying to be almost completely programmatic.

这篇关于要么调用AppDelgate要么调用ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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