嗨,我对ios非常新,在我的项目中我使用网络服务确定没问题
在我的mainView控制器中,当我点击它时我添加了一个按钮,我使用post方法调用服务 而且我也很快从我的服务器得到回复
这里我的主要问题是我从我的后台类调用我的服务,为此我在这里使用协议来获取服务的响应和我存储在我的数组列表中的总响应
当数组列表计数为“0”时,我只显示一条警告消息,当它有记录时,我会像其下面的代码一样推送到另一个视图控制器
但是当我们进入我的其他区块以下时,很快它就没有移动(我的意思是推动)到我的DetailsClass为什么这里有什么问题可以让任何身体帮助我
- (IBAction)details:(id)sender {
NSDictionary *mainDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"1234",@"scancode" ,
nil];
[BP postServieCalling:@"myurl here" :mainDictionary];
}
//Protocol method for getting response from services
- (void) PostCallService: (NSMutableArray*)mainDictyionary{
NSLog(@"final response here %@",mainDictyionary);
if (mainDictyionary.count == 0) {
NSLog(@" if block");
}else{
NSLog(@" else block");
DetailsClass *details = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailsClass"];
[self.navigationController pushViewController:details animated:YES];
}
}
答案 0 :(得分:2)
当您从Web服务获得响应时,响应不在主线程中。所有UI操作都应在主线程中执行。使用下面的代码将你的else块放在主线程中。
// For Objective c
dispatch_async(dispatch_get_main_queue(), ^{
DetailsClass *details = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailsClass"];
[self.navigationController pushViewController:details animated:YES];
});
-
// For Swift
dispatch_async(dispatch_get_main_queue()) { () -> Void in
DetailsClass *details = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailsClass"];
[self.navigationController pushViewController:details animated:YES];
}