我使用MBProgressHUD作为指标。你知道它在执行其他方法时使用了一个单独的线程。当我想使用NSURLConnection
时,它的委托没有正确调用。
这是我所拥有的(@implementation 文件):
- (void)viewDidLoad {
[super viewDidLoad];
[self hudShowWithLabel];
}
-(void)hudShowWithLabel {
HUD = [[MBProgressHUD alloc] initWithView: self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Loading";
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}
-(void)myTask {
responseData = [NSMutableData data];
NSLog(@"Is%@ main thread", ([NSThread isMainThread] ? @"" : @" NOT"));
NSString *requestURL = @"http://someurl";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:requestURL]];
(void)[[NSURLConnection alloc] initWithRequest:request delegate: self];
}
运行时,我可以看到它myTask
不在MainThread
. 我该如何解决这个问题?