16XIB_Empty_LifeCycle_Flip_ModalPop_AlertForm_从UIAlertView粘贴协议

一、XIB文件
项目:XIB_Review0311
1.1

ViewController1 *VC1 = [[ViewController1 alloc]initWithNibName:@"ViewController1" bundle:nil];

注:Nib就是XIB
1.2创建ViewController2时,忘记勾选XIB的情况
1.2.1 新建文件

1.2.2 设置名字与ViewController2一样

1.2.3 拖拽View

1.2.4 运行出错:未关联,未设置出口

1.2.5 关联文件

生命周期

- (void)viewDidLoad{
    [super viewDidLoad];
    NSLog(@"视图已经加载完成。");
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSLog(@"视图将要显示");
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    NSLog(@"视图已经显示");
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    NSLog(@"视图将要消失");
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    NSLog(@"视图已经消失");
}

页面翻转

//跳转方式1:
//通过切换根视图控制器,来切换任意两个ViewController之间的跳转
- (IBAction)flipView:(id)sender
{
    ViewController2 *vc2 = [[ViewController2 alloc]init];
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    window.rootViewController = vc2;
    //vc1→vc2翻页动画
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:3];
    //**************对window做动画************
 //当vc1→vc2时,vc1.view从window上移除是瞬时性动作,所以对vc1.view做动画是没有效果的。
    //在界面跳转的整个过程中,window始终存在,且不会变动,所以,可以对window做一个动画效果
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
    [UIView commitAnimations];
}

项目:FlipView0311

页面翻转2:
模态弹出
ModalPop_0311
ViewController1.m

//两个ViewController之间实现界面跳转的第二种方式:
//模态弹出:弹出ViewController2
- (IBAction)changeView:(id)sender
{
    //1.创建vc2
    ViewController2 *vc2 = [[ViewController2 alloc]init];
    //2.实现模态弹出(无需移除vc1,即可弹出vc2)
    [self presentViewController:vc2 animated:YES completion:nil];
}

ViewController2.m

//让vc2的View消失
- (IBAction)dismiss:(UIButton *)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

代理协议的使用步骤
1.设置代理 delegate:self
2.粘贴协议方法(从UIAlertView.h文件中)
3.实现协议方法

自学UIActionSheet控件
新推出的UIAlertController

你可能感兴趣的:(16XIB_Empty_LifeCycle_Flip_ModalPop_AlertForm_从UIAlertView粘贴协议)