2017-05-04 156 views
0

我有两个UIAlertController可以显示 - 一个用于注册一个帐户,另一个用于登录。他们可以提供一个可选的消息。UIAlertController消息不会显示

func present(alertController: UIAlertController? = nil, message: String? = nil) { 
    self.currentAlertController = alertController ?? self.currentAlertController 
    self.currentAlertController.message = message 
    (UIApplication.shared.delegate as! AppDelegate).window?.rootViewController?.present(self.currentAlertController, animated: true, completion: nil) 
} 

它看起来像消息通过函数进行。

"Email or password invalid"

但后来它不会显示。

Nothing here

我不能说,如果我失去了一些东西基本,或有还有一些关于UIAlertController我不知道的。

+0

你为什么要引用rootViewController而不是执行操作的currentVC导致显示警报? – SeanLintern88

+0

另外我相信消息必须在初始化程序中设置?它也很奇怪,你保留一个参考:/因为你得到所有你需要做的动作回调? – SeanLintern88

+1

尝试显示警报并在 – ColdGrub1384

回答

0

切换当前动作和信息的设置的伎俩。

func present(alertController: UIAlertController? = nil, message: String? = nil) { 
    self.currentAlertController = alertController ?? self.currentAlertController 
    (UIApplication.shared.delegate as! AppDelegate).window?.rootViewController?.present(self.currentAlertController, animated: true, completion: nil) 
    self.currentAlertController.message = message 
} 

另一件事是,初始化UIAlertController开始说起,如果你想在消息开始空白,但允许它在稍后更新时,该消息应该是""而不是nil