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 :)來顯示和隱藏你的活動指標。