0

I need to use AlertView because it is also compatible with iOS7.

I tried to make this code in my UITableViewController:

func alertView(View: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
    println("in alertView")
    switch buttonIndex {
    case 1: println("1")
    case 0: println("2")
    default: println("nil")
    }
}

@IBAction func entryPoint(sender: AnyObject) {
    var alert = UIAlertView()
    alert.delegate = self
    println("Pressed")
    alert.title = "Enter Input"
    alert.addButtonWithTitle("Done")
    alert.addButtonWithTitle("Cancel")
    alert.alertViewStyle = UIAlertViewStyle.PlainTextInput
    var text = alert.textFieldAtIndex(0)
    text?.placeholder = "inserisci"
    println(text?.text)
    alert.show()
}

But it seems that he can not call his delegate (func alertView()).

When I try to start the application:
Show AlertView correctly but when I press the buttons the following happens:
"Done" - nothing happens
"Cancel" - wrote nil in the log

Thanks.

Marcus Rossel
  • 3,196
  • 1
  • 26
  • 41
Stephany
  • 994
  • 1
  • 7
  • 18

1 Answers1

0
func showAlert(){
var createAccountErrorAlert: UIAlertView = UIAlertView()

createAccountErrorAlert.delegate = self

createAccountErrorAlert.title = "Oops"
createAccountErrorAlert.message = "Could not create account!"
createAccountErrorAlert.addButtonWithTitle("Dismiss")
createAccountErrorAlert.addButtonWithTitle("Retry")

createAccountErrorAlert.show()

}

func alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int){

switch buttonIndex{

case 1:
    NSLog("Retry");
break;
case 0:
    NSLog("Dismiss");
    break;
default:
    NSLog("Default");
    break;
    //Some code here..

}

}

It print dismiss when i click on dismiss button.

MAC113
  • 1,444
  • 12
  • 19