IOS8之后增加了UIAlertController类,它可以表示UIAlertView和UIActionSheet.它继承自UIViewController。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window.backgroundColor=[UIColor whiteColor];
    [self.window makeKeyAndVisible];

    ViewController *vc=[[ViewController alloc]init];
    UINavigationController *nvc=[[UINavigationController alloc]initWithRootViewController:vc];
    self.window.rootViewController=nvc;
    return YES;
}
//
//  ViewController.m
//  AlertVC
//
//  Created by City--Online on 15/5/25.
//  Copyright (c) 2015年 XQB. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame=CGRectMake(100, 100, 50, 50);
    [btn setTitle:@"按钮" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.layer.borderWidth=2.0;
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];

}
-(void)btnClick:(id)sender
{
//    UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
//
//    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//        textField.text=@"name";
//        textField.clearsOnBeginEditing=YES;
//    }];
//    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//        textField.text=@"password";
//        textField.clearsOnBeginEditing=YES;
//    }];

    UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction *actionOk=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSLog(@"确定");
    }];
    UIAlertAction *actionCancel=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        NSLog(@"取消");
    }];
    [alert addAction:actionOk];
    [alert addAction:actionCancel];
    [self presentViewController:alert animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

最新文章

  1. CentOS6.3编译安装Memcached
  2. display:block 不起作用
  3. PHP基础之 继承(一)
  4. PHP、Java输出json格式数据
  5. PHP获取毫秒时间戳,利用microtime()函数
  6. POJ-1155 TELE (树形DP+分组背包)
  7. Raspberry Pi无线路由器篇
  8. Tree HDOJ--2682
  9. iOS---There was an internal API error 错误
  10. [Lua]基于cc.load('mvc') .ViewBase索引资源方案
  11. session与cookie的关系
  12. 乘法逆元...Orz
  13. 3dmax 3dmax计算机要求 3dmax下载
  14. Nginx 11阶段的顺序处理
  15. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project triage: Compilation failure [ERROR] No compiler is provided in this environment.
  16. CentOS7.3安装Go运行和开发环境
  17. javascript中的 return false和return true
  18. 细说tomcat之集群session共享方案
  19. Java作业(一)
  20. OOA/OOD&UML部分

热门文章

  1. Jersey构建Restful风格的Webserivces(三)
  2. javascript中string与int之间的转换
  3. .net4.0重新注册IIS 的方法
  4. SQL Server 维护计划(数据库备份)
  5. WPF wpf中按钮操作权限控制
  6. httprunner 使用总结
  7. django项目中使用项目环境制作脚本 通过终端命令运行脚本文件
  8. 双向链表的实现——c++
  9. MySQL(增删改查补充)
  10. [bug]小程序弹出层滚动穿透问题修复