iphone - IOS UITableView contentOffSet 不再隐藏从推送的详细 View 返回时的标题

标签 iphone ios uitableview header hidden

我在 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/

相关文章:

ios - Swift 3 - 以编程方式构建带有图像和标签的按钮

iphone - 带分页的动态 UIScrollView

iphone - 逐帧动画

iphone - 为什么我更愿意为每个新线程或 NSOperation 创建一个 NSManagedObjectContext 而不是在主线程上调用核心数据?

ios - 无法将类型 'UIBarButtonItem' 的值转换为 'UITableViewCell'

iphone - 如何在 IndexPath 处使用 reloadRows 更新行

ios - iOS 核心数据应用程序上的 "Expected a type"错误

ios - 当应用程序变为事件状态时,文件已加密或不是数据库消息

iphone - 由于辅助功能设置未检测到 iOS 手势

ios - ./configure 参数为 iOS 构建 C 库