如何解决标题栏阻碍了TableView
| 我正在构建第一个基本的选项卡式应用程序,将其中一个视图用作导航控制器,将显示一个视图控制器。 用户在第一个表格视图中选择类别时遇到问题,如屏幕截图所示:http://www.cl.ly/7YOF 当将tableviewcontroller的另一个实例加载并推到Navigationcontroller的堆栈上时,标题栏将阻塞该表: http://www.cl.ly/7ZRz 表格视图选择逻辑如下: -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { KHCategory * selectedItem = [categoryArray objectAtIndex:indexPath.row]; 如果(selectedItem.categories.count> 0){ KHCategoryTableViewController * nextCategoryController = [[[KHCategoryTableViewController alloc] init]; nextCategoryController.categoryArray = [[NSArray alloc] initWithArray:selectedItem.categories]; nextCategoryController.title = selectedItem.labelValue; [self.navigationController pushViewController:nextCategoryController动画:是]; [nextCategoryController版本]; }其他{ NSLog(@ \“显示详细视图\”); } } 编辑: 我应该清楚地知道,KHCategoryTableViewController的实例是我NavigationController的根,而NavController连接到TabController的第一个选项卡。解决方法
有两件有趣的事情:它缩小了20像素(状态栏的大小),并且您的行“ nextCategoryController.title = ... \”似乎没有任何作用。所以...
1)我假设您没有使用
setStatusBarHidden
?
2)看起来navController的东西不起作用。您能否提供来自创建tabBar和NavController的appDelegate的代码?
3)添加此代码,然后尝试从子类别ViewDidLoad
方法调用[self dumpWindow: @\"VDL\"]
。每当检查我的视图结构是否正确时,我都会发现它非常宝贵。
- (void) dumpWindowFrom:(NSString *) fromText {
[self dumpViews: nil from:fromText];
}
void dumpViewsRecursive(UIView* view,NSString *text,NSString *indent) {
Class cl = [view class];
NSString *classDescription = [cl description];
if ([text compare:@\"\"] == NSOrderedSame)
NSLog(@\"%d: %@ %@ %@\",(int)view,classDescription,NSStringFromCGRect(view.frame),view.hidden ? @\"Inv\" : @\"Vis\");
else
NSLog(@\"%d: %@ %@ %@ %@\",text,view.hidden ? @\"Inv\" : @\"Vis\");
for (NSUInteger i = 0; i < [view.subviews count]; i++)
{
UIView *subView = [view.subviews objectAtIndex:i];
NSString *newIndent = [[NSString alloc] initWithFormat:@\" %@\",indent];
NSString *msg = [[NSString alloc] initWithFormat:@\"%@%d:\",newIndent,i];
dumpViewsRecursive (subView,msg,newIndent);
[msg release];
[newIndent release];
}
}
- (void) dumpViews: (UIView *) view {
dumpViewsRecursive (( (!view) ? [[UIApplication sharedApplication] keyWindow] : view),@\"\",@\"\");
}
- (void) dumpViews: (UIView *) view from:(NSString *) fromText{
dumpViewsRecursive ((!view) ? [[UIApplication sharedApplication] keyWindow] : view,fromText,@\"\");
}
4)您总是可以作弊并添加:
CGRect frame = [nextCategoryController.view frame];
frame.origin.y = frame.origin.y+20.0;
[nextCategoryController.view setFrame:frame];
, 检查KHCategoryTableViewController的视图的autoResizingMask。
iPhone开发人员中心的UINavigationController概述说:
注意:因为空间量大
自定义视图可用的内容可能有所不同
(取决于另一个的大小
导航视图),则您的自定义视图
autoresizingMask属性应为
设置为灵活的宽度,
高度。在显示视图之前,
导航控制器
自动定位并调整其大小
以适应可用空间。
, 当我针对iOS 4.3而非iOS 5构建此问题时,该问题已解决。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。