开发者

More than one view on one screen on iPhone/iPad?

I would like to build custom tab menu on top of the screen, similar to one you see in Numbers app. I thought I could divide screen beetween two views: one on top for tabs and one bigger for selected tab view. Is that possible? Can I have 2 active views&view c开发者_StackOverflowontrollers?


Of course it is possible. You can add views from view controllers as a subview of your current root view controller's view.

Doing this (assume this is inside a UIViewController subclass):

UIViewController *newViewController = [[UIViewController alloc] init];
[self.view addSubview:newViewController.view];

is perfectly fine.

But also consider if you really need multiple view controllers and not just additional views. From what I get from your description, I think it can be implemented with just one view controller with additional views.

Regarding your tabbed menu implementation, doesn't UITabBarController fit your needs? It is more common for tabbed interfaces in iOS apps to use this kind of tab bar, not the desktop OS tab bar where the tabs are at the top.


As I could get from variety of sources, view controller is meant to control one view that occupies application window, so doing tabbed menu with multiple views is not possible.

There may be folowing possibilities:

  • storing current tab position in some king of application level singleton
  • adding new view when appropriate tab is selected
  • redrawing tab menu when view is selected (either in new view or retrieved from stack)

Does anybody have any nicer idea?


Try this:

 UIView *contentView1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
 UIView *contentView2=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

 [self.view addSubView:contentView1];
 [self.view addSubView:contentView2];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜