UINavigationController -> UITabBarController -> UIViewController -> UITableView
I have an UINavigationController with an UITabBarController as its rootViewController, Then put an UITableView in one of the tab(UIViewController)
When i switch to one of the tabController which contains an UITableView, The first cell of the tableView under navigation bar. If i push another view controller, then pop back, the tableview relayout right. 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
override var topLayoutGuide:UILayoutSupport {
get { return (self.parentViewController?.topLayoutGuide)! }
}
override var bottomLayoutGuide:UILayoutSupport {
get { return (self.parentViewController?.bottomLayoutGuide)! }
}
(Objective C)
(id<UILayoutSupport>) topLayoutGuide {
return self.parentViewController.topLayoutGuide;
}
(id) bottomLayoutGuide { return self.parentViewController.bottomLayoutGuide; }
(void) 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); }
(void) 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); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.