I am loading a page by pressing a table view cell. I put an if statement :
if ([webViewController webView].loading == YES) {
NSLog(@"Its loading!");
if (act == nil) {
NSLog(@"Its nil");
act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
act.color = [UIColor blackColor];
} else {
act.hidden = NO;
}
act.center = self.view.center;
[act startAnimating];
} else {
[act stopAnimating];
[act setHidden: YES];
}
But the NSLog never shows up so it is never called. But when i deploy it to my iPhone it takes A LONG TIME to load but it is still never called. What is happening here?
UPDATE – SORROUNDING CODE
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"TOUCHED CELL!");
// Push the web view controller onto the navigation stack - this implicitly
// creates the web view controller's view the first time through
[[self navigationController] pushViewController:webViewController animated:YES];
// Grab the selected item
RSSItem *entry = [[channel items] objectAtIndex:[indexPath row]];
// Construct a URL with the link string of the item
NSURL *url = [NSURL URLWithString:[entry link]];
// Construct a request object with that URL
NSURLRequest *req = [NSURLRequest requestWithURL:url];
// Load the request into the web view
[[webViewController webView] loadRequest:req];
if ([webViewController webView].loading == YES) {
NSLog(@"Its loading!");
if (act == nil) {
NSLog(@"Its nil");
act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
act.color = [UIColor blackColor];
act.center = self.view.center;
[self.view addSubview:act];
} else {
act.hidden = NO;
}
act.center = self.view.center;
[act startAnimating];
} else {
[act stopAnimating];
[act setHidden: YES];
}
webViewController = nil;
webViewController = [[WebViewController alloc] init];
}
I’m not sure what you’re trying to do here. If you want to show an activity indicator while the web view is loading, you should put that code in the webViewController. (The view controller your code is in won’t be visible after you push the web view controller anyway.)
Ensure that the webViewController is delegate of the webView, and then override webViewDidStartLoad: and webViewDidFinishLoad: (and webView:didFailLoadWithError:) to show and hide your activity indicator.