【发布时间】:2014-11-17 02:22:42
【问题描述】:
在完成块中触发方法的正确方法是什么(如果甚至建议这样做)?现在,我有一个 IBAction,它调用一个下载信息的方法,该方法带有一个完成块,表示信息是否已成功检索。如果是这样,我想推送一个显示该信息的视图控制器,但目前什么都没有发生。我猜它与主线程、gcd 等有关...
__weak YTTMSetupViewController *weakSelf = self;
[mc downloadJson:^(BOOL success) {
if(success){
NSLog(@"sucess. metric count - %i",(int)mc.collection.count);
//info was downloaded. Push new view controller with info
YTTMMetricTableViewController *mtvc = [self.storyboard instantiateViewControllerWithIdentifier:@"YTTMMetricTableViewController"];
mtvc.group = (WAGroup*)[[WAMetricCollection sharedInstance].collection lastObject];
mtvc.hidesBottomBarWhenPushed = YES;
[weakSelf.navigationController pushViewController:mtvc animated:YES];
}
else{
NSLog(@"failure");
//display failure UI
}
NSLog(@"end of downloading");
[HUD dismissAfterDelay:0.5f animated:YES];
}];
【问题讨论】:
-
您可以尝试从 dispatch_asynch 调用 pushViewController,延迟 0.0 秒。通常,它可以工作。
标签: ios objective-c xcode objective-c-blocks