I have four tab controllers, one of them has a UIWebView in the view controller. I created a new thread to load web content in my webView when the app started, so when the web is finished load, it is ready for users to view when they tab to the view controller.
My problem is, the webVIew does not load request in the new created thread at all, but it is working when I put loadRequest in viewDidLoad. I spend one solid day to find the solution but no luck at all.
This is my code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
[NSThread detachNewThreadSelector:@selector(doStuff) toTarget:self withObject:nil];
return self;
}
- (void)doStuff
{
NSLog(@"Starting a new thread ...");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
url = [NSURL URLWithString:@"http://www.myURL.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[newsWebView loadRequest:request];
[pool release];
}
Can someone solve my problem? Thank you very much.