开发者

iPhone "View-based application" template: how is the view controller xib loaded?

I'm a little rusty on my Cocoa, and have a simple question. When I make a "View-based application" in XCode 4, I get a main window xib, an app delegate, and a UIViewController subclass and xib. The main window xib includes the UIViewController subclass as an object. But I don't see a call to "ini开发者_运维技巧t" on this UIViewController anywhere in code or in the inspector. How did this view controller get initialized? I guess an embedded object's "init()" just magically get called somehow?


Please have a look at when exactly do Interface Builder items get instantiated?, I've provided an answer which describes the process of nib loading.


self.window.rootViewController = self.viewController;

they are connected trough the MainWindow.xib file

if you want to customize stuff when a viewcontroller is loaded from xib/nib, you need to overwrite the method - (id)initWithCoder:(NSCoder *)inCoder in the viewcontroller

example:

- (id)initWithCoder:(NSCoder *)theCoder {

    self = [super initWithCoder:theCoder];

    if(self) {

        // your fancy stuff here!
    }

    return self;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜