I'm quite new to objective-c so i'm thinking a lot about best practices. My current problem is that I'm asking myself how to build my own kind of TabBar below the navigationBar
. I created two UIButton
s which should switch the subviews below the buttons.
Just to illustrate my architecture — it should look more or less like the header in the Gowalla app: http://cl.ly/7pQv
Of course I could just create two subviews and use removeFromSuperview
and addSubview
.
But isn't there a better way to organize them? Maybe by using a UIViewController
? But that would be some kind of nesting which 开发者_运维百科Apple doesn't recommend, isn't it? Because I don't want to change the whole view of the active navigationController
-view. My UIButton
s should stay in place, just want to switch content below …
Thank you very much!
There are a lot of ways to do this. One is to stack views on top of each other and set the alpha to 0.0 for the views you want to hide. The buttons then are simple UIButtons (as you indicated). You can do most of the work in Interface Builder (although it gets kinda messy).
Advantages: quick and dirty, no need to add/remove. Disadvantages: all the code for the "different views" is in one class which can make things messy.
There are other ways, but frankly, the amount of code in my opinion (as well as the support and the fact Apple might ding you) don't really make them worth it.
精彩评论