视图加载后更改子视图内容(可可触摸)

时间:2009-11-05 16:33:52

标签: iphone cocoa-touch sdk

我正在尝试创建自己的标签栏实现,使用工具栏而不是标签栏(以启用新“标签栏”的自定义)。为了实现这一点,我需要能够在按下按钮时在视图之间切换。

目前,我的视图包含tabBar子视图和customView子视图。后者需要在newTabBarController的按钮回调中切换。有人能告诉我怎么做这个吗?基本上我想要与子视图的presentModalViewController相同的效果。简单地将我的视图指针设置为不同的视图不起作用。

以下是一些示例代码:

- (void)viewDidLoad{
  customView = selectedViewController.view;
  [self.view addSubView:customView];
  [self.view addSubView:newTabBarController.view];
}

- (void)buttonHandler:(id)sender {
  NewViewController newController = [[NewViewController alloc] init];
  // what to do now??
}

要明确:newTabBarController不从UITabBarController继承。它是UIViewController的子类。

1 个答案:

答案 0 :(得分:0)

如果您计划保留这些视图,我会将它们全部添加到superview并使用bringSubviewToFront:和sendSubviewToBack:来管理用户看到的那个。

//what to do now??
[self.view addSubView:newController.view];
[customView sendSubviewToBack];

来自iPhone应用程序编程指南:

  

要重新排序其父级内的现有子视图,请调用父视图的bringSubviewToFront:,sendSubviewToBack:或exchangeSubviewAtIndex:withSubviewAtIndex:方法。使用这些方法比删除子视图并重新插入它们要快。

相关问题