У вас было две ошибки,
первая, вам нужно представить второе предупреждение в имени UIAlertController, а не в имени UIAlertAction
self.present(secondAlert, animated: true)
не имя метода alert2
self.present(alert2, animated: true)
второй, вам нужно вызвать первый обработчик предупреждений alertController метод UIAlertAction, например alert2 not alert2 ()
firstAlert.addAction(UIAlertAction(title: "Option A", style: .default, handler: alert2 ))
fullответ
override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)
let firstAlert = UIAlertController(title: "Title", message: "some message", preferredStyle: .alert)
firstAlert.addAction(UIAlertAction(title: "Option A", style: .default, handler: alert2 ))
firstAlert.addAction(UIAlertAction(title: "Option B", style: .default, handler: nil))
firstAlert.addAction(UIAlertAction(title: "Option C", style: .default, handler: nil))
firstAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(firstAlert, animated: true)
}
func alert2(alert: UIAlertAction!) {
//Put second alert code here:
let secondAlert = UIAlertController(title: "Title", message: "some message", preferredStyle: .alert)
secondAlert.addAction(UIAlertAction(title: "Option A", style: .default, handler: nil ))
secondAlert.addAction(UIAlertAction(title: "Option B", style: .default, handler: nil))
secondAlert.addAction(UIAlertAction(title: "Option C", style: .default, handler: nil))
secondAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(secondAlert, animated: true)
}