我正在构建我的第一个基本选项卡式应用程序,其中一个视图作为将显示视图控制器的导航控制器。
我遇到问题,用户从第一个表格视图中选择一个类别,如屏幕截图所示: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]; if (selectedItem.categories.count > 0) { KHCategoryTableViewController *nextCategoryController = [[KHCategoryTableViewController alloc] init]; nextCategoryController.categoryArray = [[NSArray alloc] initWithArray:selectedItem.categories]; nextCategoryController.title = selectedItem.labelValue; [self.navigationController pushViewController:nextCategoryController animated:YES]; [nextCategoryController release]; } else { NSLog(@"show detail view"); } }
编辑: 我应该清楚,KHCategoryTableViewController的一个实例是我的NavigationController的根,NavController连接到TabController的第一个选项卡。
答案 0 :(得分:4)
两个有趣的事情:它测量20像素(状态栏的大小)和你的行“nextCategoryController.title = ...”似乎没有做任何事情。所以......
1)我假设您没有使用setStatusBarHidden
?
2)看起来navController的东西不起作用。你能从创建tabBar和NavController的appDelegate中提供代码吗?
3)添加此代码,然后尝试从子类别[self dumpWindow: @"VDL"]
方法调用ViewDidLoad
。每当检查我的视图结构是否正确时,我发现它非常宝贵。
- (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: %@ %@ %@ %@", (int)view, text, classDescription, NSStringFromCGRect(view.frame), 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];
答案 1 :(得分:0)
检查KHCategoryTableViewController视图的autoResizingMask。
iPhone开发中心的UINavigationController概述说:
注意:因为空间量大 可用于自定义视图可能会有所不同 (取决于另一个的大小 导航视图),您的自定义视图 autoresizingMask属性应该是 设置为具有灵活的宽度和 高度。在显示您的视图之前, 导航控制器 自动定位和调整大小 以适应可用空间。
答案 2 :(得分:0)
当我针对iOS 4.3而不是iOS 5构建时,此问题已得到解决。