@IBAction func 修改昵称(sender: AnyObject) { let 昵称弹窗 = UIAlertController(title: "修改昵称", message: "请输入您的新昵称", preferredStyle: .Alert)
昵称弹窗.addTextFieldWithConfigurationHandler { (textField: UITextField!) -> Void in textField.placeholder = "新的昵称" textField.keyboardType = UIKeyboardType.NumbersAndPunctuation textField.clearButtonMode = .Always }
let 取消 = UIAlertAction(title: "取消", style: .Cancel, handler: nil)
let 新昵称 = (昵称弹窗.textFields?.first)! as UITextField
let 确定 = UIAlertAction(title: "确定", style: .Default, handler: { (action: UIAlertAction) -> Void in
let 输入的新昵称 = 新昵称.text! let 信息 = ["type": "nickname", "nickname": "\(输入的新昵称)"]
let 验证网址 = "http://hgzrt.com/"
let 转码验证网址 = 验证网址.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
if 输入的新昵称 != "" {
Alamofire.request(.POST, 转码验证网址, parameters: 信息) .responseJSON(completionHandler: { Response in switch Response.result{ case .Success(let json): //第三方swiftyjson解析 let jsondict = JSON(json)
let 是否成功 = jsondict["msg"].string ?? ""
switch 是否成功{
case "设置成功":
userDefault.setObject(true, forKey: "logined") 本机登录状态 = true
let alertVC5 = UIAlertController(title: "设置成功", message: "你GET了一个华丽的昵称", preferredStyle: .Alert) self.presentViewController(alertVC5, animated:true, completion: nil) delay(3){ self.presentedViewController?.dismissViewControllerAnimated(false, completion: nil) self.viewDidLoad() }
default: let alertVC3 = UIAlertController(title: "GET一个新问题", message: "如果不是网络不给力,请联系通通微信:jd887717", preferredStyle: .Alert) self.presentViewController(alertVC3, animated:true, completion: nil) delay(10){ self.presentedViewController?.dismissViewControllerAnimated(false, completion: nil) }
}
case .Failure(let error): print("\(error)") } })
}
})
昵称弹窗.addAction(取消) 昵称弹窗.addAction(确定) self.presentViewController(昵称弹窗, animated: true, completion: nil)
}
不懂的找我,具体不解释那么多了,我是整容通(hgzrt.com)产品经理,从小白开始自学撸码,在整容通app里面我的id是通通。
|
swift按钮如何添加弹窗事件进行修改昵称或者密码等内容
最新推荐文章于 2024-06-20 20:31:31 发布