gpt4 book ai didi

ios - 在 block 内推送 View Controller 不起作用

转载 作者:行者123 更新时间:2023-11-29 10:36:11 25 4
gpt4 key购买 nike

在完成 block 中触发方法的正确方法是什么(如果推荐的话)?现在,我有一个 IBAction 调用一个方法来下载信息,完成 block 表示信息是否成功检索。如果是的话,我想推送一个显示该信息的 View Controller ,但目前什么也没有发生。我猜它与主线程、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];
}];

最佳答案

不确定这是否是正确的方法,但它奏效了。

我添加了一个将 vc 推送到主线程的方法:

        [weakSelf performSelectorOnMainThread:@selector(pushDetail) withObject:nil waitUntilDone:YES];

完成的代码:

__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
[weakSelf performSelectorOnMainThread:@selector(pushDetail) withObject:nil waitUntilDone:YES];
}
else{
NSLog(@"failure");
//display failure UI
}
NSLog(@"end of downloading");
}];

}

-(void)pushDetail{
__weak YTTMSetupViewController *weakSelf = self;
YTTMMetricTableViewController *mtvc = [self.storyboard instantiateViewControllerWithIdentifier:@"YTTMMetricTableViewController"];
mtvc.group = (WAGroup*)[[WAMetricCollection sharedInstance].collection lastObject];
mtvc.hidesBottomBarWhenPushed = YES;
[weakSelf.navigationController pushViewController:mtvc animated:YES];

}

关于ios - 在 block 内推送 View Controller 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26964569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com