2016-10-19 7 views
1

Как показать или подключиться к новому ViewController при нажатии кнопки на предупреждение?Swift - нажать действие предупреждения, чтобы показать новый ViewController

enter image description here

Это мой код

let alert = UIAlertController(title: validateQRObj.responseDescription, message: validateQRObj.productName, preferredStyle: .alert) 
let action = UIAlertAction(title: "OK", style: .default) { (action) -> Void in 
    let viewController = self.storyboard?.instantiateViewController(withIdentifier: "ProductDetialViewController") 
    self.present(viewController!, animated: true, completion: nil) 
} 
alert.addAction(action) 
self.present(alert, animated: true, completion: nil) 
+4

Какая у вас проблема с кодом, который вы опубликовали? – rmaddy

ответ

0

Контроль сопротивления от View Controller 1 (желтая точка) в любом месте на View Controller 2, а затем нажмите на Segue. Покажите инспектору атрибутов и Идентификатору идентификатора Storyboard Segue идентификатор VC2

Если это ответ, который вы искали, не забудьте, кроме ответа.

func alert(){ 

    let alertController = UIAlertController(title: "Open View Controller. ", message: "Press Ok to open View Controller number 2.", preferredStyle: UIAlertControllerStyle.alert) 
    let ok = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: {(action) -> Void in 
    //The (withIdentifier: "VC2") is the Storyboard Segue identifier. 
    self.performSegue(withIdentifier: "VC2", sender: self) 
}) 

    alertController.addAction(ok) 
    self.present(alertController, animated: true, completion: nil) 
} 
+0

Это работа! спасибо –

0

Для меня это не работает. Я сделал:

func alert(){ 
    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let twop = storyboard.instantiateViewController(withIdentifier: "Accueil") as! Accueil 
    let alertController = UIAlertController(title: "Open new View !", message: "Clic to ok", preferredStyle: UIAlertControllerStyle.alert) 
    let ok = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: {(action) -> Void in 
     self.navigationController?.show(twop, sender: self) 
    }) 

    alertController.addAction(ok) 
    self.present(alertController, animated: true, completion: nil) 
} 

и теперь это работает!

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

  • Нет связанных вопросов^_^