开发者

How to use a UIButton to Change Views

开发者 https://www.devze.com 2023-03-23 04:51 出处:网络
How can I changed the view in iPhone development using an UIButton. I do 开发者_开发技巧not want to use a toolbar. Thank you

How can I changed the view in iPhone development using an UIButton. I do 开发者_开发技巧not want to use a toolbar. Thank you


  1. You must have a root view controller
  2. This root view controller switches between the two views.

Something like this:

- (IBAction)switchViews:(id)sender {
if (self.vc1 == nil) {
self.vc1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
[self.vc2 removeFromSuperview];
[self.view addSubView:vc1];
vc2 = nil;
}
else {
self.vc2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.vc1 removeFromSuperView];
[self.view addSubView:vc2];
vc1 = nil;
}
}
0

精彩评论

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