// // FourthViewController.m // UI3_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "FourthViewController.h" @interface FourthViewController () @end @implementation FourthViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor yellowColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(20, 100, self.view.frame.size.width-40, 50); btn.backgroundColor = [UIColor whiteColor]; [btn setTitle:@"按钮" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } - (void)btnClicked { if (self.view.superview) { //移除子视图 [self.view removeFromSuperview]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
// // ThirdViewController.m // UI3_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "ThirdViewController.h" @interface ThirdViewController () @end @implementation ThirdViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor greenColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(20, 100, self.view.frame.size.width-40, 50); btn.backgroundColor = [UIColor whiteColor]; [btn setTitle:@"按钮" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } - (void)btnClicked { if (self.view.superview) { //移除子视图 [self.view removeFromSuperview]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
// // SecondViewController.m // UI3_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "SecondViewController.h" @interface SecondViewController () @end @implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor blueColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(20, 100, self.view.frame.size.width-40, 50); btn.backgroundColor = [UIColor whiteColor]; [btn setTitle:@"按钮" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } - (void)btnClicked { if (self.view.superview) { //移除子视图 [self.view removeFromSuperview]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
转载于:https://www.cnblogs.com/0515offer/p/4638609.html