导航栏影响 UITableViewController

Navigation bar influence UITableViewController

我的故事板中有一个 UITableViewController 与一个 UINavigationController 相连。当我向下滚动我的 table 时,我可以看到行转到 "navigation bar".

的背面

简单检查了一下,我发现导航栏不影响 table 大小(导航栏似乎在我的 table 前面)。自从我 select table size:

-(CGFloat)tableView:(UITableView *)tableViews heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    CGFloat value = tableViews.frame.size.height;

    NSLog(@"Table size -> %f",value);

    return value/2;

}

他 returns 大小相同 os 我的 window...我可以做些什么来使 "navigation bar" 影响我的大小 table?

你有几个选择。尝试以下操作之一:

  1. 从 table 视图框架高度中减去导航栏和状态栏的高度。

    CGFloat value = tableViews.frame.size.height - CGRectGetMaxY(self.navigationController.navigationBar.frame);
    
  2. 不要将 table 视图放在导航栏后面。通过将以下行添加到 table 视图控制器的 viewDidLoad:

    来解决此问题
    self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeRight;
    

    这可以防止 table 视图进入导航栏或工具栏下方。

再补充一点。如果您希望所有行具有相同的高度,请不要实施 heightForRowAtIndexPath 方法。相反,只需设置 table 视图的 rowHeight 属性.