0

我通过按表格视图单元格加载页面。我把一个if语句:webView加载不被称为

 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]; 
} 

但NSLog的一直没有出现,因此不会被调用。但是当我将它部署到我的iPhone时,需要很长的时间才能加载,但它仍然不会被调用。这里发生了什么?

更新 - 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]; 

    } 
+1

上下文事项。这个代码的功能是什么?什么代码围绕它? – NJones 2011-12-18 05:18:44

+0

这是在uitableview委托协议方法: – user973985 2011-12-18 07:45:29

+0

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { – user973985 2011-12-18 07:47:07

回答

2

我不知道你想在这里做什么。如果要在加载Web视图时显示活动指示符,则应将该代码放入webViewController中。 (反正你推Web视图控制器后视图控制器你的代码是将不可见)。

确保webViewController是web视图的委托,然后覆盖webViewDidStartLoad:和webViewDidFinishLoad:(web视图和:didFailLoadWithError :)来显示和隐藏你的活动指标。