【发布时间】:2012-09-26 18:34:37
【问题描述】:
我使用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 中。我该如何解决这个问题?
【问题讨论】:
标签: nsurlconnection nsurlconnectiondelegate