我有一个应用程序,其中包含许多地图视图。我需要检查互联网连接是真还是假。如果错误,将显示一条uialert消息,uiactivity Indicator
将显示(将开始)....其工作正常..
但是,当我突然连接互联网时,那个联络指标并没有停止。还在跑步。
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
ActiviyuInc.hidden = true
showmethod()
}
func showmethod () {
if Reachability.isConnectedToNetwork() == false {
print("Internet connection FAILED")
let alert = UIAlertView(title: "No Internet Connection", message: "Make sure your device is connected to the internet.", delegate: nil, cancelButtonTitle: "OK")
alert.show()
if Reachability.isConnectedToNetwork() == false {
ActiviyuInc.hidden = false
ActiviyuInc.startAnimating()
}
else {
ActiviyuInc.hidden = true
ActiviyuInc.stopAnimating()
}
}
}
当我的应用程序处于运行状态时,当我连接到互联网时,我的uiactivityIndicator
仍未停止...
帮帮我!!!
答案 0 :(得分:1)
尝试停止主线程上的Activity,
dispatch_async(dispatch_get_main_queue()) { () -> Void in
ActiviyuInc.hidden = true
ActiviyuInc.stopAnimating()
}
答案 1 :(得分:1)
就这样做。
if Reachability.isConnectedToNetwork() == false {
print("Internet connection FAILED")
let alert = UIAlertView(title: "No Internet Connection", message: "Make sure your device is connected to the internet.", delegate: nil, cancelButtonTitle: "OK")
alert.show()
ActiviyuInc.hidden = false
ActiviyuInc.startAnimating()
} else {
ActiviyuInc.hidden = true
ActiviyuInc.stopAnimating()
}