I'm using MBProgressHUD as an indicator. And you know it's using a separate thread when while executing some other method. When I want to use NSURLConnection
, its delegation is not calling properly.
Here what I have (@implementation file):
- (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];
}
While running, I can see that myTask
is not in MainThread
. How could I solve this problem?