iOS7 table view embedded in tab bar doesn't display last cell

后端 未结 5 833
花落未央
花落未央 2021-01-02 10:10

In my storyboard, I have a View controller (embedded in a navigation controller). Inside the view controller I have a tab bar controller, and inside a tab a table view contr

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 10:24

    I had the same problem, and the up-voted answers did not solve it. See my answer to a similar question, Tab Bar covers TableView cells in iOS7.

    I solved the issue by manually setting the table view's frame in the table view controller's viewWillAppear: method (as suggested by Matt Quiros) to the height of the screen - (status bar height + nav bar height + tab bar height).

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        // Adjust height of tableview (does not resize correctly in iOS 7)
        CGRect tableViewFrame = self.tableView.frame;
        tableViewFrame.size.height = [self heightForTableView];
        self.tableView.frame = tableViewFrame;
    }
    
    - (CGFloat)heightForTableView
    {
        return CGRectGetHeight([[UIScreen mainScreen] bounds]) -
               (CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]) +
                CGRectGetHeight(self.navigationController.navigationBar.frame) +
                CGRectGetHeight(self.tabBarController.tabBar.frame));
    }
    

    If anyone finds a better solution to this problem, please share!

提交回复
热议问题