【发布时间】:2015-06-07 12:38:34
【问题描述】:
我正在制作一个应用程序,以便可以将数据保存到表格视图中,并且我想以某种方式使用 UIAlertView 控制器,以便人们可以使用它来创建一个新的单元格(任务),但我知道如何在其中创建一个 textField一个 UIAlertView 但如何使用 textField 数据并在 UIAlertView 操作按钮中使用它!
@IBAction func addNewTask() {
var alertController = UIAlertController(title: "Add A New Task", message: "Add The Correct Information To Add A New Task!", preferredStyle: .Alert)
// Create the actions
var Exit = UIAlertAction(title: "Add Task", style: UIAlertActionStyle.Default) {
UIAlertAction in
NSLog("OK Pressed")
}
var cancelAction = UIAlertAction(title: "Exit App", style: UIAlertActionStyle.Cancel) {
UIAlertAction in
NSLog("User Exited The App!")
exit(2)
}
alertController.addTextFieldWithConfigurationHandler { (textField: UITextField!) -> Void in
// Here you can configure the text field (eg: make it secure, add a placeholder, etc)
}
// Add the actions
alertController.addAction(Exit)
alertController.addAction(cancelAction)
// Present the controller
self.presentViewController(alertController, animated: true, completion: nil)
}
这是代码,但我如何使用来自alertController.addTextFieldWithConfigureationHandler 的数据并将其放入Exit 操作中!所以我想要做的主要事情是当用户在文本框中键入并单击退出时,标签将从 textField 更改为该文本,但不使用 viewController!我正在使用 Swift,Xcode 6.3.1
谢谢,
乔治·巴洛
附言很抱歉这个冗长的问题!
【问题讨论】:
标签: ios swift uialertview