我是创建两个可切换的UIViews(每个UIView有一些子视图)的位堆栈。由于我不是IB,我想以编程的方式来做。1 UIViewController和2以编程方式切换UIViews
我已经尝试将我的子视图添加到我的第一个UIView,然后与第二个相同,然后切换到这样的视图。
if ([self.setView superview]) { [self.setView removeFromSuperview]; [self.view addSubview:contentView]; self.navigationItem.title = @"BaseLine"; } else { [self.contentView removeFromSuperview]; self.view = setView; self.navigationItem.title = @"Settings"; }
但只有正常工作的是“标题”,没有出现在UIViews上。 UIView似乎是好的,因为当我使用
self.view = contentView; or self.view = setView;
都正确显示子视图。
请有人踢我这个正确的方向。
TNX
编辑: 也指向该解决方案,也许有毛病我初始化中的loadView
CGRect screenRect = [[UIScreen mainScreen] applicationFrame]; contentView = [[UIView alloc] initWithFrame:screenRect]; setView = [[UIView alloc] initWithFrame:screenRect]; self.view = contentView;
我尝试添加它第一次[自我。视图中添加..],但该应用崩溃,所以就用这个
EDIT2
根控制器UITableViewController..it是在导航视图和带有两个UIVies选择一个小区此UIVieController(percView)之后被分配
ShakeControl *percView = [[ShakeControl alloc] init]; [self.navigationController pushViewController:percView animated:YES]; [percView release];
EDIT3 开关由按钮来完成,但细做,因为我使用了很多次,它的工作
这是我原本认为有效的代码,但没有。 – Vanya 2010-11-10 16:08:14
你是否通过重写loadView来初始化self.view?假设self.view不是零,它的框架大小和位置是否正确? – 2010-11-10 16:16:17
是的,我重写loadView和self.view有应用程序框架大小的视图 – Vanya 2010-11-10 16:24:46