iOS编程------UIAlertController

//
//  AppDelegate.h
//  UIAlertViewController
//
//  Created by l on 15/9/4.
//  Copyright (c) 2015年 . All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end








//
//  AppDelegate.m
//  UIAlertViewController
//
//  Created by l on 15/9/4.
//  Copyright (c) 2015年 . All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    return YES;
}











//
//  ViewController.h
//  UIAlertViewController
//
//  Created by l on 15/9/4.
//  Copyright (c) 2015年 . All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end






//
//  ViewController.m
//  UIAlertViewController
//
//  Created by l on 15/9/4.
//  Copyright (c) 2015年 . All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic, strong) UIAlertController *alertController;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    /*
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"AlertController" message:@"this is a alertConttoller" preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
    //添加事件
    [alertController addAction:cancel];
    //模态显示alertController
    //presentViewController: 为模态显示方式
    //animated: 为模态显示的时候是否做动画
    //completion: 为显示出来后,要执行的block块
    [self presentViewController:alertController animated:YES completion:nil];//写在这里是错误的!!!
  */

    _alertController = [UIAlertController alertControllerWithTitle:@"AlertController" message:@"this is a alertController" preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
    [_alertController addAction:cancel];


    // Do any additional setup after loading the view, typically from a nib.
}
//一个controller 什么时候它的view才会被显示出来呢?
//当controller.view被添加到父视图上面的时候
//先执行viewWillAppear 后执行viewDidAppear
// 因此 当视图被显示出来的时候,执行的是 vieDidAppear
//同时只能给view设置一个rootVC,如果把一个controller的展示写在rootVC的viewDidLoad 和loadView里面,会产生逻辑混乱,window不知道该加载哪个根视图控制器.

- (void)viewDidAppear:(BOOL)animated{

    [self presentViewController:_alertController animated:YES completion:nil];

}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值