UIAlertView
is deprecated, so use it for iOS 7 compatibility. Otherwise, use UIAlertController
.
let alertView = UIAlertView()
alertView.message = "here"
alertView.addButtonWithTitle("Ok")
alertView.show()
Set the alertViewStyle
and the delegate
.
let alertView = UIAlertView()
alertView.alertViewStyle = .PlainTextInput
alertView.title = "Title"
alertView.message = "Message"
alertView.addButtonWithTitle("Cancel")
alertView.addButtonWithTitle("Ok")
alertView.delegate = self
alertView.show()
You don't tell your class to conform to a protocol (no wonder this thing is deprecated!). Just implement this method, and have faith that it gets called. View.textFieldAtIndex(0)
gives you a handle on the UITextField
.
override func alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int){
switch buttonIndex{
case 1:
println("Ok")
if let textField = View.textFieldAtIndex(0) as UITextField? {
println("textField:: \(textField.text)")
}
case 0:
println("Cancel")
default:
println("Default shouldn't get called")
}
}