开发者

What is the use of the line [super loadView]

I just wanted to know whether i am write or not I have been working with iPhone technology for about 4 months and the only piece of code that i write in the loadView method is to add some views like the buttons,labels etc to the current instance of the viewControll开发者_如何转开发er class so that when i use its view property all those views are added to the window. But the piece of line that really bugs me is

[super loadView];

what is the use of this method all i came to know from diff sites is that "if i don't use this method my app will crash" that's not a reason i am looking for, so i made a virtual concept that this line might give us a black instance of UIView and then we add all the views

[self.view addSubView:btn];
to the view provided to us by this line.

So all i wanted to know is that am i right or wrong, i think the

[super loadView];
line does more than that can anyone give me a detailed explanation or provide me a link from where i can refer this concept.


-loadView is called by your view controller when the view is actually needed. Implement it if you are creating your view manually and not in IB. You are responsible for making sure the view property has a view assigned to it by the time this method is finished. Do not call [super loadView] or [self loadView] by yourself!

Official docs: "Your custom implementation of this method should not call super."

http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/loadView


The super keyword calls the superclass' implementation of this method. So you probably are right on the money (I don't do objective-c) and this call initializes all the stuff you need to display your app.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜