swift 3通过操作按钮和当前控制器发出警报

时间:2017-02-20 06:59:10

标签: swift uialertcontroller

我正在从AlertController发出警报的所有人,但我想要在行动按钮之后" OK"按下,打开LoginController,我该怎么做?我试着像下面这样做,但是它没有工作

AlertController:

class AlertController: NSObject {

class func showErrorWith(title:String? = nil, message:String? = nil, controller: UIViewController , complition:(() -> ())?){
    let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in


//            let storyboard = UIStoryboard(name: "Main", bundle: nil)
//            let viewController = storyboard.instantiateViewController(withIdentifier :"LoginVC")
//            self.present(viewController, animated: true)
//            

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

2 个答案:

答案 0 :(得分:4)

之所以会发生这种情况,是因为你在这段代码中称为self.present,这就是NSObject。 只需致电controller.present(viewController, animated:true);

答案 1 :(得分:2)

@inject('params')
@observer