【发布时间】:2011-05-04 21:00:59
【问题描述】:
我的问题是,如果我的网络请求在ViewWillAppear 触发之前或之后不久未完成,则后退按钮将无法恢复其可见性。
我有一个基于导航的 iPhone 4.0 应用程序,使用了简单的 Root 和 Detail 视图设置。
我正在处理从 web 服务返回的数据,所以当我在其ViewDidLoad 函数中推送我的详细视图时,我在单独的线程中调用我的 web 服务方法,并且 Iphone 生命周期在主线程上执行它的操作。我必须禁用/隐藏后退按钮,直到 Web 请求完成(或失败),所以我在 ViewDidLoad 中调用 self.navigationItem.hidesBackButton = YES;,在我的 Web 请求完成或失败后触发的委托函数中调用 self.navigationItem.hidesBackButton = NO;。
我已经尝试了以下方法:
[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 中隐藏按钮会浪费我这么多时间。
【问题讨论】:
标签: iphone button navigation hide back