我有一个非常轻的 ViewController,它在 viewDidLoad 中什么都不做。我将这个 View 推到 navigationController 之上。从 block 内部调用执行此操作的方法。在调用 showView 之后,我添加了一个 NSLog,该日志在控制台中的打印速度非常快,但是加载 View 需要很多时间……我真的不明白可能发生了什么……有什么想法吗???
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
[self showView];
NSLog(@"EXECUTED");
});
- (void) showView{
TestViewController *test = [[TestViewController alloc]init];
[self.navigationController pushViewController:test animated:NO];
}
最佳答案
来自 ABAddressBookRequestAccessWithCompletion
的文档:
The completion handler is called on an arbitrary queue. If your app uses an address book throughout the app, you are responsible for ensuring that all usage of that address book is dispatched to a single queue to ensure correct thread-safe operation.
您应该确保在主线程上调用您的 UI 代码。
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error {
dispatch_async(dispatch_get_main_queue(), ^{
[self showView];
NSLog(@"EXECUTED");
});
});
关于objective-c - pushViewController 占用过多显示 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13996931/