我在 Root View Controller 中使用下面的代码来隐藏 UITableView 的 header ( header 中有一个 UISearchbar)。 It works when the app starts up and displays the tableView.. However afterwards, when a row is selected, the detail view is pushed, and the user pops the detail view, the uitableview header is now visible in the root view, which is not如我所料。
相关函数如下:
- (void) viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
self.tableView.contentOffset
= CGPointMake(0, self.tableView.tableHeaderView.frame.size.height);
//it's as if the line above is ignored on when returning from a pushed detail view
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// theContentOffSet works when I put it hear, but then the user can see it which is not desired
}
行'[self.navigationController setNavigationBarHidden:YES animated:animated];'肯定是问题的一部分,因为没有它,代码可以工作并且 tableView header 滚出 View 。然而, Root View 的要求是隐藏导航栏,但显示在详细 View 中。
最佳答案
看了一会,发现了下面这个帖子https://devforums.apple.com/message/315519#315519这解决了这个问题。
-(void)viewWillAppear:(BOOL)animated
{
[self performSelector:@selector(updateContentOffset) withObject:nil afterDelay:0.0];
}
- (void)updateContentOffset
{
self.tableView.contentOffset = CGPointMake(0, savedContentOffsetY);
}
当然,在viewWillDisappear
中你可以保存内容偏移如下:
savedContentOffsetY = self.tableView.contentOffset.y;
在你的viewDidLoad
中,
savedContentOffsetY = self.tableView.tableHeaderView.frame.size.height;
关于iphone - IOS UITableView contentOffSet 不再隐藏从推送的详细 View 返回时的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6143875/