如何在导航条下的iOS UITableView?

我已经设定

NavigationController.NavigationBar.Translucent = true; 

然后添加表格并将其设置为RootView Frame,并且:

  public override void ViewDidLayoutSubviews() { base.ViewDidLayoutSubviews(); float y = this.TopLayoutGuide.Length; table.ContentInset = new UIEdgeInsets (y, 0, 0, 0); } 

但是,我有导航栏下的表格滚动条(我使用monotouch):

在这里输入图像说明

刚刚放

navigationBar.translucent = NO; 你的问题将解决:)

其他选项是,

把下面的代码。

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if([self respondsToSelector:@selector(edgesForExtendedLayout)]) [self setEdgesForExtendedLayout:UIRectEdgeBottom]; } 

另一个select是..

为什么UIViewController在UINavigationBar下扩展,而UITableViewController没有?

尝试这个:

  if([self respondsToSelector:@selector(edgesForExtendedLayout)]) { self.edgesForExtendedLayout = UIRectEdgeNone; self.automaticallyAdjustsScrollViewInsets = NO; } 

我用这个简单的代码解决了任务:

 table.ScrollIndicatorInsets = new UIEdgeInsets(64, 0, 0, 0); 

这工作对我tableView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0)

大多数情况下,引入魔术常量的解决scheme并不会扩展,例如,如果下一个iPhone引入了不同的导航栏高度,我们将不得不更新我们的代码。

幸运的是,苹果为我们提供了克服这个问题的更清晰的方法,例如topLayoutGuide :

当视图控制器在屏幕的最前面时,topLayoutGuide属性起作用。 它表示您不希望出现在半透明或透明UIKit栏(如状态栏或导航栏)后面的内容的最高垂直范围,

以编程方式,您可以使用以下代码片段实现(也可以通过IB实现相同):

 override func viewDidLoad() { super.viewDidLoad() automaticallyAdjustsScrollViewInsets = false tableView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor), tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor), tableView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor), tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor) ]) } 

注意:在iOS 11中不推荐使用topLayoutGuide ,我们应该使用UIView的safeAreaLayoutGuide属性。