objective-c Tab Bar 覆盖了 iOS7 中的 TableView 单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19325677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tab Bar covers TableView cells in iOS7
提问by JuJoDi
I have a custom tableViewController that I'm adding to a TabBarController with
我有一个自定义 tableViewController,我将它添加到 TabBarController 中
self.tabBarController.viewControllers = [NSArray arrayWithObjects:someOtherViewController, customTableViewController, nil];
self.tabBarController.selectedIndex = 1;
The issue I'm having is that the last 1.5 tableViewCells are being covered by the tab bar at the bottom of the screen on an iPhone 4 running iOS7. When I use the iOS Simulator - iPhone Retina (4-inch) / iOS 7.0 the issue still exists.
我遇到的问题是最后 1.5 个 tableViewCells 被运行 iOS7 的 iPhone 4 屏幕底部的标签栏覆盖。当我使用 iOS Simulator - iPhone Retina (4-inch) / iOS 7.0 时,问题仍然存在。
What is the correct way to make the tableView line up with the top of the tabBar at the bottom of the screen without using 'magic numbers'?
在不使用“幻数”的情况下,使 tableView 与屏幕底部的 tabBar 顶部对齐的正确方法是什么?
回答by dariaa
Try this for your CustomViewController:
为您的 CustomViewController 试试这个:
- (void)viewDidLoad
{
[super viewDidLoad];
UIEdgeInsets adjustForTabbarInsets = UIEdgeInsetsMake(0, 0, CGRectGetHeight(self.tabBarController.tabBar.frame), 0);
self.scrollView.contentInset = adjustForTabbarInsets;
self.scrollView.scrollIndicatorInsets = adjustForTabbarInsets;
}
回答by Hans One
It's an iOS 8 solution but it may work on iOS 7 to: Go to storyboard > select table view controller > uncheck "Under Bottom Bars". That's it!
这是一个 iOS 8 解决方案,但它可能适用于 iOS 7:转到故事板 > 选择表视图控制器 > 取消选中“在底部栏下”。就是这样!


回答by jaredsinclair
Setting the contentInsetof your table view with a .bottomvalue of 49 points should correct this.
将contentInsettable view 的.bottom值设置为 49 点应该可以纠正此问题。
Under the right configurations, setting YESfor the new UIViewController property on iOS 7 called automaticallyAdjustsScrollViewInsetsshould correct this, but (again) it depends upon a lot of other factors (view hierarchy, parent view controller's settings, et cetera).
在正确的配置下,YES在 iOS 7 上设置新的 UIViewController 属性automaticallyAdjustsScrollViewInsets应该可以纠正这个问题,但是(再次)它取决于很多其他因素(视图层次结构、父视图控制器的设置等)。
回答by Matthew Quiros
The accepted answer doesn't quite work for me--my set up is a little different. I'm programatically creating my view controllers. My app's root is a tab bar controller, one tab is a navigation controller, whose root is a UIViewControllerwith a table view as the main view.
接受的答案对我来说不太适用——我的设置有点不同。我正在以编程方式创建我的视图控制器。我的应用程序的根是一个标签栏控制器,一个标签是一个导航控制器,其根是一个UIViewController以表视图为主视图的。
What works for me though is when I manually computed the table view's height and set it in the frame when alloc-initing the table view. The general formula is:
但是对我有用的是当我手动计算表视图的高度并将其设置在框架中时分配初始化表视图。一般公式为:
screen height - (status bar height + nav bar height + tab bar height)
屏幕高度 - (状态栏高度 + 导航栏高度 + 标签栏高度)
回答by shadox
CGFloat bottom = self.tabBarController.tabBar.frame.size.height;
NSLog(@"%f",bottom);
[self.tableview setScrollIndicatorInsets:UIEdgeInsetsMake(0, 0, bottom, 0)];
self.tableview.contentInset = UIEdgeInsetsMake(0, 0, bottom, 0);
回答by Ssemmandarobert
Embed your table controller in a navigation controller. 1. select the view in story board. 2. On menu bar select Editor -> embed in -> navigation controller.
将您的表格控制器嵌入到导航控制器中。1.在故事板中选择视图。2. 在菜单栏上选择编辑器 -> 嵌入 -> 导航控制器。
Hope that helps
希望有帮助
回答by Steph Sharp
I have a similar view hierarchy to Matt Quiros: UITabBarController -> UINavigationController -> UIViewController -> UITableViewController (embedded as a subview of the UIViewController). The other answers didn't work in my case, and I had to set the table view's frame manually in the table view controller's viewWillAppear:method.
我有一个与Matt Quiros类似的视图层次结构:UITabBarController -> UINavigationController -> UIViewController -> UITableViewController(作为 UIViewController 的子视图嵌入)。其他答案在我的情况下不起作用,我必须在表视图控制器的viewWillAppear:方法中手动设置表视图的框架。
- (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, please share!
如果有人找到更好的解决方案,请分享!
回答by Paul Newman
You can also implement viewDidLayoutSubviewsand use bottomLayoutGuideto get the height of the tab bar:
您还可以实现viewDidLayoutSubviews并使用bottomLayoutGuide来获取标签栏的高度:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
CGFloat bottomOffset = self.bottomLayoutGuide.length;
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, bottomOffset, 0);
}
回答by Michael Pirotte
Even though changing the contentInset of your table View is a working solution, I find it better to make sure your table view stops before the Tabbar.
尽管更改 table View 的 contentInset 是一个可行的解决方案,但我发现最好确保 table view 在 Tabbar 之前停止。
As Paul Newman said, using the bottomLayoutGuide is a good thing, specially if you are using autolayout. In My case adding a constraint to the bottom of the tableview linking to the top of the BottomLayoutGuide was a clean solution, this is an example with Storyboard, but it can be done in code as well.
正如 Paul Newman 所说,使用 bottomLayoutGuide 是一件好事,特别是如果您使用自动布局。在我的情况下,在链接到 BottomLayoutGuide 顶部的 tableview 底部添加约束是一个干净的解决方案,这是 Storyboard 的一个示例,但它也可以在代码中完成。


Hope it helps.
希望能帮助到你。
回答by DominicanCoder
I think this would work better for you:
我认为这对你更有效:
After [super viewDidLoad];
后 [super viewDidLoad];
try the following code:
试试下面的代码:
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;

