你好,我有我已經宣佈AlertViewFunction這樣我如何傳遞一個控制器的功能
func displayAlertMessage(userMessage: String,//controller){
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)
myAlert.addAction(okAction);
self.presentViewController(myAlert, animated: true, completion: nil)
}
的問題是一個工具類,我不能使用self
這裏
self.presentViewController(myAlert, animated: true, completion: nil)
我想通過一個控制器到這個功能,所以我可以這樣使用
controller.presentViewController(myAlert, animated: true, completion: nil)
如何通過控制器來自任何ViewController。比方說,如果我在LoginViewController
Utility().displayAlertMessage(Message.INTERNETISNOTCONNECTED,//controller)
非常感謝您 – hellosheikh
@hellosheikh我很高興我能幫助! –