我试图加载我的视图,然后使用自定义segue转换到它。问题是它的滞后程度相当大,我似乎无法找到除了正在呈现的视图在segue期间加载的源。
- (IBAction)continueButtonClicked:(id)sender{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
IntroViewController *imageLoader = (IntroViewController*)[storyboard instantiateViewControllerWithIdentifier:@"imageLoader"];
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// present
[self customSegue:imageLoader];
// dismiss
[self dismissViewControllerAnimated:YES completion:nil];
});
}
我已经达到了整合中央调度的程度,但我认为没有区别。我对GCD几乎没有经验。我有相同的segue到另一个视图,它加载没有滞后就好了。
答案 0 :(得分:0)
您只能在主线程上显示UI,并且您尝试在后台线程上执行。试试这个:
- (IBAction)continueButtonClicked:(id)sender
{
dispatch_async(dispatch_get_main_queue(), ^{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
IntroViewController *imageLoader = (IntroViewController*)[storyboard instantiateViewControllerWithIdentifier:@"imageLoader"];
// present
[self customSegue:imageLoader];
});
}
我删除了[self dismissViewControllerAnimated:YES completion:nil];
行,因为关闭呈现视图控制器会导致呈现的视图控制器无法展开segue。