首页 > 编程语言 > 详细

swift学习之-- UIAlertViewController -alert

时间:2015-12-08 08:40:19      阅读:151      评论:0      收藏:0      [点我收藏+]
//
//  ViewController.swift
//  alertView
//
//  Created by su on 15/12/7.
//  Copyright © 2015年 tian. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
   
   var controller:UIAlertController!
    override func viewDidLoad() {
//        1.强制对Optional值进行拆包(unwrap)
//        2.声明Implicitly Unwrapped Optionals值,一般用于类中的属性
     
       
        super.viewDidLoad()
         //创建UIAlertController实例
       
        controller = UIAlertController(title: "我是**", message: "爱我的点击确定", preferredStyle: UIAlertControllerStyle.Alert)
       
       
        controller.addTextFieldWithConfigurationHandler { (textFiled:UITextField!) -> Void in
            textFiled.placeholder = "我们都爱Swift"
        }
        //创建action
//                let action = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default) { (paramAction:UIAlertAction!) -> Void in
//                    print("果然是真爱啊")
//                }
        let action = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default) { (paramActoin:UIAlertAction!) -> Void in
            if let textFields = self.controller.textFields {
                let txtFields = textFields as [UITextField]
                let txt = txtFields[0].text
                print("输入的内容是:\(txt)")
               
            }
        }
        //让alertController添加action
        controller.addAction(action)

       
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.presentViewController(controller, animated: true, completion: nil)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
 

swift学习之-- UIAlertViewController -alert

原文:http://www.cnblogs.com/tian-sun/p/5028038.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!