美文网首页
Swift自学记录

Swift自学记录

作者: 这是一个很萌的昵称 | 来源:发表于2018-10-09 17:27 被阅读0次

    alertView的使用

     let alertView = UIAlertView()
    
        alertView.delegate = self
    
        alertView.alertViewStyle = UIAlertViewStyle(rawValue: 2)!;
    
        alertView.title = "标题"
    
        alertView.message = "这个是UIAlertView的默认样式"
    
        alertView.addButton(withTitle: "取消")
    
        alertView.addButton(withTitle: "好的")
    
        alertView.show()
    

    后来发现 这个方法还是很方便的

        let alertController = UIAlertController(title: "添加相册",
    
                                                message: "请输入相册名称", preferredStyle: .alert)
    
        alertController.addTextField {
    
            (textField: UITextField!) -> Void in
    
            textField.placeholder = "相册名称"
    
        }
    
    
    
        let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
    
        let okAction = UIAlertAction(title: "好的", style: .default, handler: {
    
            action in
    
            //也可以用下标的形式获取textField let login = alertController.textFields![0]
    
            let name = alertController.textFields!.first!
    
            print("用户名:\(name.text)")
    
        })
    
        alertController.addAction(cancelAction)
    
        alertController.addAction(okAction)
    
        self.present(alertController, animated: true, completion: nil)
    

    swift 页面跳转

        let ptotoView = PhotoController()
        //跳转
        self.navigationController?.pushViewController(ptotoView , animated: true)
    

    相关文章

      网友评论

          本文标题:Swift自学记录

          本文链接:https://www.haomeiwen.com/subject/lkdyaftx.html