I am making a application so data can be saved to a Table View and I wanted to use the UIAlertView Controller in a way so people can use it to create a new Cell (task) but I know how to make a textField in a UIAlertView but how do use the textField data and use it in a UIAlertView Action button!
@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)
}
This is the code but how can I use the data from the alertController.addTextFieldWithConfigureationHandler
and put it in the Exit
Action! So the main thing I want this to do just know is when the user types in the textbox and clicks Exit a label will change to that text from the textField but without using a viewController! I am using Swift, Xcode 6.3.1
Thanks,
George Barlow
p.s. Sorry for the longwinded question!
In your
UIAlertAction
calledExit
(btw, you should consider changing the name to something likeexit
orexitAction
), you can access theUITextField
and its contents in the following way: