开发者

different ways to call window? in objective-c

i was just wondering : in different tutorials, we usually use the first 2 lines, instead of the 2 last lines that are set by default , for the same purpose :

        [wind开发者_开发问答ow addSubview:viewController.view];
        [window makeKeyAndVisible];

        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];

(because the rootViewController is normally set by default.) Does it change anything?

Thanks


In the first case:

 [window addSubview:viewController.view]

You are adding your View Controller view's as a subview of your window.

while in

 [self.window.rootViewController = self.viewController]

You are simply identifying that the root View Controller for this window will be self.viewController. However this is basically the same thing because by identifying this as your root viewController you are also making this viewController's view a subView of window.

Basically the first way was the old way to do it, since the property rootViewController is new in iOS 4.0. The new way just makes it clearer that this is the top view of your application.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜