开发者

Main XIB not showing?

开发者 https://www.devze.com 2023-04-11 13:12 出处:网络
I currently am having a issue with my main XIB. I am using iOS 5 Beta 7 so it shouldn\'t be a problem with that. Anyway, this is how I am doing it in the app delegate to show the main view:

I currently am having a issue with my main XIB.

I am using iOS 5 Beta 7 so it shouldn't be a problem with that. Anyway, this is how I am doing it in the app delegate to show the main view:

.h

UIWindow *window;
Game3ViewController *viewController;

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) Game3ViewController *viewController;

.m

@synthesize window = _window;
@synthesize viewController = _viewController;

In the applicationDidFinishLaunching method:

//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.viewController = [[[Game3ViewController alloc] initWithNibName:@"Game3ViewController" bundle:nil] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;

Then the开发者_运维知识库 dealloc:

- (void)dealloc {
    [_window release];
    [_viewController release];
    [super dealloc];
}

The problem is that I am not sure if I am now supposed to do something in the MainWindow.XIB, am I? I thought this code would do everything for me but all I see when I load the app is a white window. Am I supposed to connect my Main View in the MainWindow.xib?

Anyway, if you look at Xcode's default templates for a Single View Application in Xcode Beta 7, you will see that there isn't even a MainWindow.xib, so that is why I am confused. How would I go upon fixing this?

Thanks!


When creating a Single View Application it will create 2 .xib. One is MainWindow.xib and the other is ViewController.xib. By default you shouldn't have to touch your App delegate because both nibs are linked already.

However, if you want to start from scratch by selecting the Window-based Template you will have to create your own View Controller later. And then to add the view controller to the window you need to do everything you have done with this in your applicationDidFinishLaunching method:

// Override point for customization after application launch.
self.viewController = [[[Game3ViewController alloc] initWithNibName:@"Game3ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;

By this I mean that you need to eliminate the first line where you are allocating your window. MainWindow.xib already does it for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号