【发布时间】:2015-06-17 04:03:33
【问题描述】:
我是一个 swift 程序员,我有 UIAlertViewController 有两个文本字段,我希望当用户点击 enter 时,键盘隐藏。但我不知道我应该做什么。这是我的代码
var alert = UIAlertController(title: "خوش آمدید", message: "لطفا نام و نام خانوادگی خود را نام ببرید" , preferredStyle: UIAlertControllerStyle.Alert)
var act = UIAlertAction(title: "تایید", style: UIAlertActionStyle.Destructive, handler: {(ACTION) in
var name = alert.textFields![0] as! UITextField
var lname = alert.textFields![1] as! UITextField
self.namet = name.text
self.lnamet = lname.text
if (self.lnamet == "" && self.namet == "")
{
self.presentViewController(alert, animated: true, completion: nil)
}
self.defaults.setObject("done", forKey: "dn")
var fulltext = " خوش اومدی " + self.namet + self.lnamet
self.txt.text = fulltext
var ntfc = UILocalNotification()
ntfc.alertBody = " برگرد " + self.namet + "!"
ntfc.fireDate = NSDate(timeIntervalSinceNow: 40)
ntfc.soundName = "Untitled.m4a"
UIApplication.sharedApplication().scheduleLocalNotification(ntfc)
})
alert.addTextFieldWithConfigurationHandler { (textField) -> Void in
textField.placeholder = "نام"
textField.clearButtonMode = UITextFieldViewMode.Always
}
alert.addTextFieldWithConfigurationHandler { (textField1) -> Void in
textField1.placeholder = "نام خانوادگی"
textField1.clearButtonMode = UITextFieldViewMode.Always
}
【问题讨论】:
-
我说的是快速,不是客观的c
-
view.endEditing(true) 也很方便!