我有一个alertview,它显示了一个文本字段,用户必须输入它作为强制。问题是如果用户点击“授权”没有输入它的alertview被关闭。我不能想出一个方法来显示给用户,它是强制的,而不关闭alertview。
编码:
函数表视图(表视图:UITableView!,didSelectRowAt索引路径索引路径:NSIndexPath!){
print("You selected cell #\(self.empNameArr[indexPath.row])!")
let alertController = UIAlertController(title: "OD Authorise", message: "", preferredStyle: UIAlertControllerStyle.Alert)
let AUTHORISE = UIAlertAction(title: "AUTHORISE", style: UIAlertActionStyle.Default, handler: {
alert -> Void in
let firstTextField = alertController.textFields![3] as UITextField
print("<><><><><><>",firstTextField.text)
})
let DENY = UIAlertAction(title: "DENY", style: UIAlertActionStyle.Default, handler: {
(action : UIAlertAction!) -> Void in
})
let CANCEL = UIAlertAction(title: "CANCEL", style: UIAlertActionStyle.Default, handler: {
(action : UIAlertAction!) -> Void in
})
alertController.addTextFieldWithConfigurationHandler { (txtRemarks : UITextField!) -> Void in
txtRemarks.font = UIFont(name: (txtRemarks.font?.fontName)!, size: 11)
txtRemarks.text = " Employee Name :\(self.empNameArr[indexPath.row]) "
txtRemarks.userInteractionEnabled=false
txtRemarks.borderStyle = UITextBorderStyle.None
}
alertController.addTextFieldWithConfigurationHandler { (txtRemarks : UITextField!) -> Void in
txtRemarks.font = UIFont(name: (txtRemarks.font?.fontName)!, size: 11)
txtRemarks.text = " From Date :\(self.leavDateArr[indexPath.row]) "
txtRemarks.userInteractionEnabled=false
txtRemarks.borderStyle = UITextBorderStyle.None
}
alertController.addTextFieldWithConfigurationHandler { (txtRemarks : UITextField!) -> Void in
txtRemarks.font = UIFont(name: (txtRemarks.font?.fontName)!, size: 11)
txtRemarks.text = " To Date :\(self.ToDate[indexPath.row]) "
txtRemarks.userInteractionEnabled=false
txtRemarks.borderStyle = UITextBorderStyle.None
}
alertController.addTextFieldWithConfigurationHandler { (txtRemarks : UITextField!) -> Void in
txtRemarks.font = UIFont(name: (txtRemarks.font?.fontName)!, size: 11)
txtRemarks.text = " Leave reason :\(self.Reason[indexPath.row]) "
txtRemarks.userInteractionEnabled=false
txtRemarks.borderStyle = UITextBorderStyle.None
}
alertController.addTextFieldWithConfigurationHandler { (txtRemarks : UITextField!) -> Void in
txtRemarks.placeholder = "Enter Your Remarks"
txtRemarks.font = UIFont(name: (txtRemarks.font?.fontName)!, size: 15)
txtRemarks.userInteractionEnabled=true
txtRemarks.borderStyle = UITextBorderStyle.Line
txtRemarks.textAlignment = NSTextAlignment.Center
}
alertController.addAction(AUTHORISE)
alertController.addAction(DENY)
alertController.addAction(CANCEL)
self.presentViewController(alertController, animated: true, completion: nil)
}
3条答案
按热度按时间e4yzc0pl1#
将类设置为UIAlertViewDelegate,并将alrtView的委托设置为类。
那就这样做
pxyaymoc2#
编辑:
如果您不想启用或禁用Authorize Action,则可以使用以下代码。
另一个仅显示消息的选项是吐司。https://github.com/scalessec/Toast
piah890a3#
您需要将手势识别器添加到UIAlertController中,以便在消除发生之前触发,您可以参考以下答案:Prevent UIAlertController to dismiss
另外,您可以使用以下代码: