zoukankan      html  css  js  c++  java
  • swift学习之-- UIAlertViewController -alert

    //
    //  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.
        }


    }
     
  • 相关阅读:
    Hlg 1740 DP求路径且按最小字典序输出.cpp
    Uestc 1720 【容斥原理】.cpp
    Uva 10112 【简单的计算几何】.cpp
    Vijos 1071 【DP之记录路径】
    Hlg 1665 【KMP】.cpp
    cf 226b 唯美思维题~.cpp
    Hlg 1049 【广搜+康拓展开】.cpp
    Hlg 1067 【状态压缩DP】.cpp
    Pythoner.CN: 中小企业IT不可错过的十大虚拟机软件 | Pythoner.CN
    OpenStack Hacker养成指南 | UnitedStack Inc.
  • 原文地址:https://www.cnblogs.com/tian-sun/p/5028038.html
Copyright © 2011-2022 走看看