Почему мое оповещение не может выполнить блокировку и не может закрыть? - PullRequest
0 голосов
/ 16 декабря 2018

Я создаю оповещение с помощью UIAlertController и добавляю в него некоторые действия.Но когда я касаюсь кнопки и ничего не меняется.(Включите кнопку отмены), так что я могу только перезапустить это приложение может решить этот вопрос.

let alert = UIAlertController(title: “my alert”, message: “some message...”, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: “button1”, style: .default, handler: { (_) in
     print(“button 1 up inside”)
}))
alert.addAction(UIAlertAction(title: “button2”, style: .default, handler: { (_) in
     print(“button 2 up inside”)
}))
alert.addAction(UIAlertAction(title: “cancel”, style: .cancel, handler: { (_) in

}))
self.present(alert, animated: true, completion: nil)

Xcode 10. построен.

Ответы [ 2 ]

0 голосов
/ 16 марта 2019

Спасибо большое!Контроллер моего представления не может закрыть это предупреждение, потому что эти коды

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

}

override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {

}
0 голосов
/ 16 декабря 2018

У меня была похожая проблема в приложении, использующем набор Sprite.Вот решение:

let connectActionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

connectActionSheet.addAction(UIAlertAction(title: "Button1", style: .default, handler: { (action:UIAlertAction) in

       //Code if this button is pressed
}))

connectActionSheet.addAction(UIAlertAction(title: "Button2", style: .default, handler: { (action:UIAlertAction) in

       //Code if button2 is pressed
}))

connectActionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

let vc = self.view?.window?.rootViewController
if vc?.presentedViewController == nil {
       vc?.present(connectActionSheet, animated: true, completion: nil)
}

Последние 4 строки сделали его работоспособным.Я надеюсь, что это поможет вам.

...