使用UIAlertController弹出消息框

//
//  ViewController.swift
//  HelloWord
//
//  Created by QHS8848 on 15/9/29.
//  Copyright © 2015年 QHS8848. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //设置背景色为白色
        self.view.backgroundColor = UIColor.whiteColor()
    }

    @IBAction func buttonClick1(sender: UIButton) {
        
        //alertController--Alert模式
        let alertController = UIAlertController(title: "AlertController", message: "使用UIAlertController来做提示对话框的测试", preferredStyle:.Alert)
        
        //OK按钮的代码块,这里点击Ok按钮以后,再次弹出一个新的Alert
        let okActionHandler = {(action:UIAlertAction!)->Void in
            let alertMessage = UIAlertController(title: "AlertAction", message: "你点击的是Ok按钮", preferredStyle: .Alert)
            alertMessage.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
            self.presentViewController(alertMessage, animated: true, completion: nil)
        }
        
        //OKButton
        let okAction = UIAlertAction(title: "OK", style: .Default, handler: okActionHandler)
        
        //Cancel按钮的事件处理代码块
        let cancelActionHander = {(action:UIAlertAction!) -> Void in
            NSLog(" Cancel Button")
        }

        //CancelButton
        let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: cancelActionHander)
        
        //将UIAlertAction添加到UIAlertController上面
        alertController.addAction(okAction)
        alertController.addAction(cancelAction)
        
        //显示
        presentViewController(alertController, animated: true, completion: nil)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}



转载于:https://my.oschina.net/u/587148/blog/512291

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值