【发布时间】:2011-12-18 03:17:43
【问题描述】:
我正在通过按下表格视图单元格来加载页面。我放了一个 if 语句:
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 时,它需要很长时间才能加载,但它仍然没有被调用。这里发生了什么?
更新 - 环绕代码
-(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];
}
【问题讨论】:
-
上下文很重要。这段代码在什么功能中?它周围有什么代码?
-
在uitableview委托协议方法中:
-
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
标签: objective-c xcode uitableview uiwebview uiactivityindicatorview