【发布时间】:2011-05-07 22:55:06
【问题描述】:
我对创建两个可切换的 UIView 有点堆栈(每个 UIView 都有一些子视图)。因为我没有 IB,所以我想以编程方式做到这一点。
我尝试将我的子视图添加到我的第一个 UIView,然后与第二个相同,然后切换到这样的视图。
if ([self.setView superview]) { [self.setView removeFromSuperview]; [self.view addSubview:contentView]; self.navigationItem.title = @"BaseLine"; } 别的 { [self.contentView removeFromSuperview]; self.view = setView; self.navigationItem.title = @"设置"; }但唯一能正常工作的是“标题”,UIViews 上什么也没有出现。 UIView 似乎还可以,因为当我使用时
self.view = contentView; 要么 self.view = setView;都正确显示子视图。
请有人把我踢到正确的方向。
tnx
编辑: 也指出解决方案,也许我在loadView中的初始化有问题
CGRect screenRect = [[UIScreen mainScreen] applicationFrame]; contentView = [[UIView alloc] initWithFrame:screenRect]; setView = [[UIView alloc] initWithFrame:screenRect]; self.view = contentView;我尝试先添加它 [self.查看添加..] 但是应用程序崩溃了,所以我使用了这个
EDIT2
根控制器是 UITableViewController..它在导航视图中,在选择一个单元格后,这个带有两个 UIVies 的 UIVieController (percView) 被分配
ShakeControl *percView = [[ShakeControl alloc] init]; [self.navigationController pushViewController:percView 动画:YES]; [percView 发布];EDIT3 开关是通过按钮完成的,但是做得很好,因为我使用了很多次并且它有效
【问题讨论】:
标签: iphone objective-c uiview uiviewcontroller