4

我有一个AppDelegatemainWindow.xib。我创建了另一个viewController并从中调用AppDelegate,它运行良好。现在我怀疑是否可以将视图控制器设置为 root 而不将其添加到mainWindow.xib. 是否必须加载我们的视图mainWindow.xib

我这样称呼视图控制器

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    self.view = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    [self.window.contentView addSubview:self.view.view];
    self.view.view.frame = ((NSView*)self.window.contentView).bounds;
}
4

3 回答 3

3

尝试使用

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

    self.viewControllerObj = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = self.viewControllerObj;

    [self.window makeKeyAndVisible];
    return YES;

}
于 2013-09-02T06:34:01.930 回答
1

尝试这个:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{   
    self.view = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = self.view;   
}
于 2013-09-02T06:09:30.687 回答
0

1.将此添加到您的 appdelegate.h

@property (strong, nonatomic) UIWindow *window;

2.在 didFinishLaunching 方法中将其添加到您的 appdelegate.m

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

return YES;
于 2013-09-02T06:39:36.057 回答