HealthKit 访问后转到 ViewController 但元素在 5 秒后显示
After HealthKit access go to ViewController but elements show after 5 seconds
在我的应用程序中,我要求访问 HealthKit,并且工作正常。我获准阅读步数和攀升的航班。权限获得授权后,我想将用户发送到新的 ViewController
。这工作正常,但 ViewController
中的元素会在 5/6 秒后显示。我已经将元素放在 ViewController
by storyboard 中。如果我添加带有代码的元素,它们会直接显示。
这怎么可能?我希望所有元素在加载 ViewController
时直接显示。
这是我用来检查 HealthKit 是否已授权并将用户发送到下一个 ViewController
:
的代码
healthManager.authorizeHealthKit { (authorized, error) -> Void in
if authorized {
let vc : AnyObject = self.storyboard!.instantiateViewControllerWithIdentifier("mainVC")
self.showViewController(vc as! UIViewController, sender: vc)
} else {
if error != nil {
println("\(error)")
}
}
}
After the user has finished responding, this method calls its completion block on a background queue.
你应该在主线程上做所有 UI 相关的事情,所以就把它分派到那里
dispatch_async(dispatch_get_main_queue()) {
let vc : AnyObject = self.storyboard!.instantiateViewControllerWithIdentifier("mainVC")
self.showViewController(vc as! UIViewController, sender: vc)
}
在我的应用程序中,我要求访问 HealthKit,并且工作正常。我获准阅读步数和攀升的航班。权限获得授权后,我想将用户发送到新的 ViewController
。这工作正常,但 ViewController
中的元素会在 5/6 秒后显示。我已经将元素放在 ViewController
by storyboard 中。如果我添加带有代码的元素,它们会直接显示。
这怎么可能?我希望所有元素在加载 ViewController
时直接显示。
这是我用来检查 HealthKit 是否已授权并将用户发送到下一个 ViewController
:
healthManager.authorizeHealthKit { (authorized, error) -> Void in
if authorized {
let vc : AnyObject = self.storyboard!.instantiateViewControllerWithIdentifier("mainVC")
self.showViewController(vc as! UIViewController, sender: vc)
} else {
if error != nil {
println("\(error)")
}
}
}
After the user has finished responding, this method calls its completion block on a background queue.
你应该在主线程上做所有 UI 相关的事情,所以就把它分派到那里
dispatch_async(dispatch_get_main_queue()) {
let vc : AnyObject = self.storyboard!.instantiateViewControllerWithIdentifier("mainVC")
self.showViewController(vc as! UIViewController, sender: vc)
}