开发者

Iphone using mainwindow.xib confusion

In a navigation based application, when I want to create and use other uiviews and uitableviews I need to create their controller and views. in an example I saw that I can simply create a new controller with .xib file, design it, and just call that xib file from my navigationcontroller.

In another example, some stuff was going on also in the mainwin开发者_运维技巧dow.xib and some new controllers and navigation items were added from the mainwindow.xib.

What is the difference between these methods? when and why I should need to open and edit the mainwindow.xib file to add a controller?


The mainwindow.xib is your UIWindow component which you can see as a representation of your iphone screen, it will always be there no matter what. In your examples when you are showing your view controller dirrctly that is because the controller is already a subview of your UIWindow which is the mainwindow.xib in the Interface Builder.

There really is no difference between the 2 methods, in the first one you are adding your controller as a subview progrmatically using:

[window addsubview:mynavcontroller]

And in the second one youbare doing it thru interface builder, you may use whichever method you feel more comfortable with.

You do not really need a controller to show a view, however they can be handy if you want to do any extra stuff such as rotating your view or loading certain data when the view is loading. That being said you could add your view as a subview of your window and it would still work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜