2015-01-02 5 views
0

Каждая ячейка в моем представлении коллекции имеет кнопку и текстовое поле.Как представить UIAlertController с точки зрения?

Когда кнопка нажата, я хочу отобразить предупреждение, если текстовое поле пуст.

В моей настраиваемое представление коллекции ячейки у меня есть:

func displayAlert(title: String, error: String) { 
var alert = UIAlertController(title: title, message: error, preferredStyle: UIAlertControllerStyle.Alert) 
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { action in 
alert.dismissViewControllerAnimated(true, completion: nil) 
})) 
self.presentViewController(alert, animated: true, completion: nil) 
} 

func redeemButtonPressed(sender: UIButton!) { 
if enterCodeTextField.text == "" { 
    displayAlert("Something went wrong", error: "Please enter a valid code") 
} 

ответ

0

Попробуйте использовать alert.show() как способ показать предупреждение.

0

Попробуйте для функции:

func redeemButtonPressed(sender: UIButton!) { 
if enterCodeTextField.text == " "{ 

     let alert = UIAlertView() 
     alert.title = "Alert Title here" 
     alert.message = "Message Here" 
     alert.addButtonWithTitle("Understood") 
     alert.show() 

    } 
Смежные вопросы