0

ViewWillAppear我的问题是,如果我的网络请求在触发之前或之后不久没有完成,则后退按钮将不会恢复其可见性。

我有一个基于导航的 iPhone 4.0 应用程序,它使用了简单的 Root 和 Detail 视图设置。我正在处理从 web 服务返回的数据,所以当我在其ViewDidLoad函数中推送我的详细视图时,我在单独的线程中调用我的 web 服务方法,并且 Iphone 生命周期在主线程上执行它的操作。我必须禁用/隐藏后退按钮,直到 Web 请求完成(或失败),所以我调用self.navigationItem.hidesBackButton = YES;ViewDidLoad 和self.navigationItem.hidesBackButton = NO;委托函数,一旦我的 Web 请求完成或失败就会触发。

我已经尝试了以下方法:

[self.navigationItem performSelectorOnMainThread:@selector(setHidesBackButton:) withObject:NO waitUntilDone:NO];
[self.navigationItem setHidesBackButton:NO];
[self.view setNeedsDisplay];
[self.navigationController.view setNeedsDisplay];

UINavigationItem *nav = self.navigationItem;
nav.hidesBackButton = NO;

根视图控制器推送代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 ArticleViewController *articleViewController = [[ArticleViewController alloc] initWithNibName:@"ArticleViewController" bundle:nil];
 NewsArticle *newsArticle = [newsItems objectAtIndex:indexPath.row];
 articleViewController.articleID = newsArticle.newsID;
 [self.navigationController pushViewController:articleViewController animated:YES];

 [newsArticle release];
 [articleViewController release];
}

详情查看控制器代码:

- (void)viewDidLoad {
 [super viewDidLoad];

 self.navigationItem.hidesBackButton = YES;
 id scrollView = [[[self webContent] subviews] objectAtIndex:0];
 if([scrollView respondsToSelector:@selector(setBackgroundColor:)] )
 {
  [scrollView performSelector:@selector(setBackgroundColor:) 
       withObject:[UIColor blackColor]];
 }

 [self getNewsArticle];
}

//Fires when the web request has finished
- (void) finish:(NewsArticle *)newsArticleFromSvc {
 self.navigationItem.hidesBackButton = NO;
 self.newsArticle = newsArticleFromSvc;
 [self bindNewsArtice];
}

任何帮助都非常感谢我几乎不能@#$&^ 相信在 UI 中隐藏一个按钮会导致我浪费这么多时间。

4

2 回答 2

1

尝试使用以下方法UINavigationItem

- (void)setHidesBackButton:(BOOL)hidesBackButton animated:(BOOL)animated
于 2010-11-04T08:09:28.410 回答
1

我无法解决这个问题。相反,我调整了我的 App Logic 以使隐藏他的后退按钮变得不必要。

于 2010-11-16T18:55:52.647 回答