我有一个视图控制器,在启动时显示SVProgressHUD,因为数据是从服务器获取的。如果在获取完成之前移回上一个视图控制器,我将如何关闭SVProgressHUD?
我试过这个:
override func viewWillDisappear(animated : Bool) {
super.viewWillDisappear(animated)
if (self.isMovingFromParentViewController()){
print("before dismiss")
SVProgressHUD.dismiss()
print("after dismiss")
}
}
我收到错误:致命错误:在解包可选值时意外发现nil
以下是视图控制器中导航回的一些代码:
override func viewWillAppear(animated: Bool) {
self.navigationItem.hidesBackButton = true
}
override func viewDidLoad() {
searchRestaurants.delegate = self
loadRestaurants()
super.viewDidLoad()
// Do any additional setup after loading the view.
//navigation bar title edit
self.navigationController!.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "Chalkboard SE", size: 17)!]
//fetch list of restaurant names from database
//set table cells to values inside array
}
override func viewDidAppear(animated: Bool) {
//SVProgressHUD.dismiss()
}
override func viewWillDisappear(animated : Bool) {
super.viewWillDisappear(animated)
if (self.isMovingFromParentViewController()){
let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
print("This is run on the background queue")
SVProgressHUD.dismiss()
})
}
}