简体   繁体   English

UITableView布局问题,(内容插入)

[英]UITableView Layout issue, (Content Inset)

UINavigationController -> UITabBarController -> UIViewController -> UITableView UINavigationController-> UITabBarController-> UIViewController-> UITableView

I have an UINavigationController with an UITabBarController as its rootViewController, Then put an UITableView in one of the tab(UIViewController) 我有一个带有UITabBarController作为其rootViewController的UINavigationController,然后将UITableView放在选项卡之一(UIViewController)中

When i switch to one of the tabController which contains an UITableView, The first cell of the tableView under navigation bar. 当我切换到其中包含UITableView的tabController之一时,导航栏下tableView的第一个单元格。 If i push another view controller, then pop back, the tableview relayout right. 如果我推另一个视图控制器,然后弹出,则tableview重新布局正确。 How to make it layout right on start. 如何在开始时进行布局。

viewWillAppear中进行布局可以解决问题

I solved it. 我解决了 This is the issue of topLayoutGuide, Fix it (Swift) by override the topLayoutGuide property 这是topLayoutGuide的问题,可以通过覆盖topLayoutGuide属性来解决(快速)

override var topLayoutGuide:UILayoutSupport {
    get { return (self.parentViewController?.topLayoutGuide)! }
}

override var bottomLayoutGuide:UILayoutSupport {
    get { return (self.parentViewController?.bottomLayoutGuide)! }
}

(Objective C) (目标C)

(id<UILayoutSupport>) topLayoutGuide {
return self.parentViewController.topLayoutGuide;

} }

  • (id) bottomLayoutGuide { return self.parentViewController.bottomLayoutGuide; (id)bottomLayoutGuide {return self.parentViewController.bottomLayoutGuide; } }

  • (void) viewWillLayoutSubviews { [super viewWillLayoutSubviews]; (无效)viewWillLayoutSubviews {[super viewWillLayoutSubviews]; //NSLog is required here, just invoke the getter, don't know why in Objective C getter is not invoked by default NSLog(@"%@", self.topLayoutGuide); //这里需要NSLog,只是调用getter,不知道为什么在Objective C中默认不调用getter NSLog(@“%@”,self.topLayoutGuide); } }

  • (void) viewDidLayoutSubviews { [super viewDidLayoutSubviews]; (无效)viewDidLayoutSubviews {[super viewDidLayoutSubviews]; //NSLog is required here, just invoke the getter, don't know why in Objective C getter is not invoked by default NSLog(@"%@", self.topLayoutGuide); //这里需要NSLog,只是调用getter,不知道为什么在Objective C中默认不调用getter NSLog(@“%@”,self.topLayoutGuide); } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM