Вот мой кодUIAlertView не возвращает соответствующее значение
import Foundation
import UIKit
class Alert: UIViewController {
class func showAlert(title: String, message: String, buttonTitle: String? = nil, buttonTitle2: String? = nil, sender: UIViewController) -> Int? {
var flag : Int?
func yes(){
flag = 1
}
func no(){
flag = 0
}
//= nil ;
if objc_getClass("UIAlertController") != nil {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
if (buttonTitle != nil){
alert.addAction(UIAlertAction(title: buttonTitle, style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) in
yes()
}))
}
if (buttonTitle2 != nil) {
alert.addAction(UIAlertAction(title: buttonTitle2, style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) in
no()
}))
}
sender.presentViewController(alert, animated: true, completion: nil)
return flag
} else {
let alert = UIAlertView()
alert.title = title
alert.message = message
alert.addButtonWithTitle(buttonTitle)
alert.addButtonWithTitle(buttonTitle2)
print("inside Else")
alert.show()
return flag
//make and use a UIAlertView
}
}
}
Проблема заключается в том, что флаг получение возвращается всегда ноль в контроллер просмотра я зову Сигнал с. Мне нужно, чтобы флаг возвращался 1, если «да» нажата, и 0, если нажата «Нет». Я застрял в этой проблеме много времени. Помогите.
Это 'UIAlertController'. 'UIAlertView' устарел. –