任何人都可以告诉我如何验证UITextFields内部UIAlertController?
除非输入两个字段,否则我需要它来阻止用户单击"保存".
到目前为止,这是我的代码:
@IBAction func btnStart(sender: AnyObject) {
var alert = UIAlertController(title: "New user",
message: "Add a new user",
preferredStyle: .Alert)
let saveAction = UIAlertAction(title: "Save",
style: .Default) { (action: UIAlertAction!) -> Void in
self.textFieldName = alert.textFields![0] as UITextField
self.textFieldEmail = alert.textFields![1] as UITextField
self.saveUser(self.textFieldName.text, email: self.textFieldEmail.text)
self.tableView.reloadData()
}
saveAction.enabled = false
let cancelAction = UIAlertAction(title: "Cancel",
style: .Default) { (action: UIAlertAction!) -> Void in
}
alert.addTextFieldWithConfigurationHandler {
(textFieldName: UITextField!) in
textFieldName.placeholder = "Enter full name" …Run Code Online (Sandbox Code Playgroud) 我需要构建一个iOS Swift单页面应用程序,它具有60:00分钟的倒数计时器.2秒后,我需要显示一个UILabel,在6秒后隐藏它,然后显示另一个文本.到目前为止这是我的代码:
var startTime = NSTimeInterval()
var timer = NSTimer()
func startCountdownTimer() {
var currentTime = NSDate.timeIntervalSinceReferenceDate()
//Find the difference between current time and start time.
var elapsedTime: NSTimeInterval = 3600-(currentTime-startTime)
//Calculate the minutes in elapsed time.
let minutes = UInt8(elapsedTime / 60.0)
elapsedTime -= (NSTimeInterval(minutes) * 60)
//Calculate the seconds in elapsed time.
var seconds = UInt8(elapsedTime)
elapsedTime -= NSTimeInterval(seconds)
//Add the leading zero for minutes and seconds and store them as string constants
let strMinutes = …Run Code Online (Sandbox Code Playgroud)