【发布时间】:2014-01-08 14:07:34
【问题描述】:
这是我的代码:
LoadViewController *loadingViewController = [[LoadViewController alloc] initWithNibName:@"LoadViewController" bundle:nil];
[self.view addSubview:loadingViewController.view];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) , ^{
[Util deleteAllObjects:@"Unit"];
for (NSDictionary *eachUnit in serviceData) {
//insert in DB
AppDelegate* appDelegate = [AppDelegate sharedAppDelegate];
NSManagedObjectContext *context = appDelegate.managedObjectContext;
Unit *unit = [NSEntityDescription insertNewObjectForEntityForName:@"Unit" inManagedObjectContext:context];
unit.id_unidade = [eachUnit objectForKey:@"id"];
unit.title = [eachUnit objectForKey:@"title"];
unit.image = [eachUnit objectForKey:@"image"];
unit.address = [eachUnit objectForKey:@"address"];
unit.desc = [eachUnit objectForKey:@"desc"];
unit.coord = [eachUnit objectForKey:@"coord"];
NSError *error;
if (![context save:&error]) {
NSLog(@"Ops,fail: %@", [error localizedDescription]);
}
}
NSLog(@"before");
[self fillUnits];
NSLog(@"after");
dispatch_async(dispatch_get_main_queue(), ^(void) {
NSLog(@"reload");
[self.tableView reloadData];
[loadingViewController.view removeFromSuperview];
NSLog(@"after reload");
});
});
它会一直显示到 NSLog(@"after"),但永远不会出现在 NSLog(@"reload") 上。 有什么线索吗??
【问题讨论】:
-
dispatch_async(dispatch_get_main_queue(), ^(void) 中的这个(void)是什么?
-
我认为我们无法从这个 sn-p 中推断出问题所在。您可能在代码中的其他地方阻塞了主队列。
-
这是该类的初始化方法的一部分...它在用户点击 UIAlertView 中的取消按钮后被调用...确实 UI 卡住了显示警报...跨度>
-
LoadViewController 在单击取消按钮后被调用,我想......对吗?这看起来不错?
-
此代码与警报在不同的类中,但是是的...单击取消按钮会调用上面的此方法
标签: ios multithreading activity-indicator