我看了很多答案,但都没有帮助。这是我以前的警报和相应动作
override func viewWillAppear(animated: Bool) {
if Reachability.isConnectedToNetwork() == true {
print("internet connection ok")
} else
{
print("internet not ok")
let alertView: UIAlertView = UIAlertView(title: "Alert ", message: "connect to internet", delegate: self, cancelButtonTitle: "settings", otherButtonTitles: "cancel")
alertView.show()
return
}
}
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int)
{
if buttonIndex == 0 {
//This will open ios devices wifi settings
UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root")!)
}
else if buttonIndex == 1
{
//TODO for cancel
exit(0)
}
}
我收到了警告:
'UIAlertView' 在iOS 9.0中已被弃用。请改用具有preferredStyle属性为UIAlertControllerStyleAlert的UIAlertController
我尝试过:
let alert = UIAlertController(title: "Alert", message: "My Alert for test", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: { (action:UIAlertAction!) in
print("you have pressed the Cancel button")
}))
self.presentViewController(alert, animated: true, completion: nil)
但是我无法将两个按钮添加并将按钮按下方法的索引路径链接到我的旧代码,我的uialert按钮没有任何动作发生。
请帮助我解决问题,如何删除这些警告并重新编写带有我的两个按钮操作的Uialert。
我是Swift的新手。您的帮助将很有用。谢谢!