我有一个包含两个UITableView
的UITabBarController
,它们都是在Storyboard中创建的。
问题在于第二个tableview的前几行显示在顶部导航栏下方,而第一个tableview则没有。即使我改变视图的顺序,第一个也能完美工作,而第二个仍然会出现问题。因此,在选项卡控制器中排名靠后的那个tableview现在也出现了同样的问题。
我没有太多的代码可以展示,因为我没有通过编程方式创建tableviews。
我有一个包含两个UITableView
的UITabBarController
,它们都是在Storyboard中创建的。
问题在于第二个tableview的前几行显示在顶部导航栏下方,而第一个tableview则没有。即使我改变视图的顺序,第一个也能完美工作,而第二个仍然会出现问题。因此,在选项卡控制器中排名靠后的那个tableview现在也出现了同样的问题。
我没有太多的代码可以展示,因为我没有通过编程方式创建tableviews。
根据您的描述,不确定具体情况,但可能有以下两种可能性:
在IB中检查您的视图控制器属性检查器。 查找“View Controller”下的“Extend Edges”选项,并取消选中“Under Top Bars”。
在ios7中,UIScrollView和所有子类似乎存在一种行为,即内容插入和偏移会自动调整,有时调整得不是很好。 您可以尝试在代码或IB中禁用它(请参阅链接了解如何: iOS 7 -- navigationController is setting the contentInset and ContentOffset of my UIScrollView)
UITabBarNavigationController
时才有效。 - Albert Bori对于任何新创建的iOS >7.0应用程序,我建议您深入了解自动布局。对于我所有旧的iOS 6应用程序,我是这样解决的:
在您的UITableViewController界面中:
bool _hasStatusBar;
bool _hasStatusBarHeight;
UIView *_blendView;
UITableViewController
实现文件中:-(void)viewWillAppear:(BOOL)animated{
_hasStatusBar = NO;
_blendView = nil;
[self.tableView reloadData];
}
-(void)viewWillDisappear:(BOOL)animated{
_hasStatusBar = NO;
_blendView = nil;
}
- (void) viewDidLayoutSubviews {
// WTF APPLE!?
if (!_hasStatusBar) {
int topBarOffset = 20;
_hasStatusBar = YES;
// Fix for iOS 7 overlaying status bar
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CGRect viewBounds = self.view.bounds;
_blendView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewBounds.size.width, topBarOffset)];
[_blendView setBackgroundColor:COLOR_MAIN];
[_blendView setOpaque:YES];
[_blendView setAlpha:1.00];
UIView *whityMacWhite = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewBounds.size.width, topBarOffset)];
[whityMacWhite setBackgroundColor:[UIColor whiteColor]];
[whityMacWhite setOpaque:NO];
[whityMacWhite setAlpha:0.80];
[_blendView addSubview:whityMacWhite];
[self.view.superview addSubview:_blendView];
}
}
}