【问题标题】:IOS UITableView contentOffSet no longer hides header on return from pushed detail viewIOS UITableView contentOffSet 不再隐藏从推送的详细视图返回时的标题
【发布时间】:2011-05-26 19:17:52
【问题描述】:

我在根视图控制器中使用下面的代码来隐藏 UITableView 的标题(标题中有一个 UISearchbar)。当应用程序启动并显示TableView时,它就会工作符合我的预期。

以下是相关功能:

- (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 标题会滚动到视图之外。然而,根视图的要求是隐藏导航栏,但在详细视图中显示。

【问题讨论】:

    标签: iphone ios uitableview header hidden


    【解决方案1】:

    看了一会,发现下面这个帖子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;
    

    【讨论】:

    • viewDidLoad 的代码行应该是'savedContentOffsetY',对吗?否则这段代码看起来很棒,我会在尝试后立即接受它作为答案。
    • 好发现,堪察加半岛。看起来“performSelector”使您能够通过 viewWillAppear 的动画解决一些时间挑战
    • 感谢您发现错字,现已更正。
    【解决方案2】:

    我已经搜索并尝试了很多,但没有任何帮助。最后,以下代码帮助了我。您可以在 viewDidLoad() 方法中添加代码:

    self.edgesForExtendedLayout = UIRectEdgeNone;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-28
      • 1970-01-01
      • 1970-01-01
      • 2011-06-29
      • 2011-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多