Иногда просто необходимо чтобы при каких либо действиях всплывало окно, так называемый Alert Controller. Ниже мы покажем с помощью какой функции его вызывать и как добавлять на него кнопки действия.
Итак приступим:
прежде всего добавляем во ViewContrller – UIAlertController Delegate.
После:
let alert = UIAlertController(title: “Внимание”, message: “Время пиёма пищи”, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: “OK”, style: .destructive, handler: { action in
switch action.style{
case .default:
print(“default”)
case .cancel:
print(“cancel”)
case .destructive:
print(“destructive”)
self.stopTimerAction()
}}))
alert.addAction(UIAlertAction(title: “Повторить”, style: .default, handler: { action in
switch action.style{
case .default:
self.userTime = 20
self.startTimerAction()
case .cancel:
print(“cancel”)
case .destructive:
print(“destructive”)
}}))
self.present(alert, animated: true, completion: nil)
Итогом будет появляется окно (изображение слева).