我希望在我的表视图控制器提取项目(来自EKEventStore)时显示UIAlertView。一旦我的所有物品都出现了,我希望警报消失。
我尝试在viewDidAppear()中解除警报,但这不起作用。我的警报就在附近。我不能在代码之后解除它以获取我的项目因为获取在其自己的线程上运行并继续执行其后的东西 - 因此,我的警报将会出现并立即消失。
let alert = UIAlertView(title: "Loading", message: "Please wait...", delegate: nil, cancelButtonTitle: "Cancel")
override func viewDidLoad() {
super.viewDidLoad()
dispatch_async(dispatch_get_main_queue()) {
let loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(50, 10, 37, 37)) as UIActivityIndicatorView
loadingIndicator.center = self.view.center;
loadingIndicator.hidesWhenStopped = true
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
loadingIndicator.startAnimating();
self.alert.setValue(loadingIndicator, forKey: "accessoryView")
loadingIndicator.startAnimating()
self.alert.show()
}
// Code to fetch my items here...
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.alert.dismissWithClickedButtonIndex(-1, animated: true)
}
答案 0 :(得分:1)
不应该在viewDidAppear()
。每次出现视图时都会viewDidAppear
加载(这就是为什么它会立即解除这一点)。
在您想要发生的所有事情都完成加载后,您需要在代码中的某处解除此问题。可能在这里:(但这取决于你的物品的取物到底是什么样的)
// Code to fetch my items here...
self.alert.dismissWithClickedButtonIndex(-1, animated: true)
}