iphone - TableView 被标题栏遮挡

标签 iphone ios ios4 uinavigationcontroller uitableview

我正在构建我的第一个基本选项卡式应用程序,其中一个 View 作为将显示 View Controller 的导航 Controller 。

当用户从第一个表格 View 中选择一个类别时,我遇到了一个问题,如屏幕截图所示:http://www.cl.ly/7YOF

当 tableviewcontroller 的另一个实例被加载并压入 navigationcontroller 的堆栈时,表格被标题栏遮挡: http://www.cl.ly/7ZRz

表格 View 选择逻辑如下:

- (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 的第一个选项卡。

最佳答案

两件有趣的事情:它向下测量 20 个像素(状态栏的大小)并且您的行“nextCategoryController.title = ...”似乎没有做任何事情。所以……

1) 我假设您还没有使用 setStatusBarHidden

2) 看起来 navController 的东西不工作。您能否提供创建 tabBar 和 NavController 的 appDelegate 代码?

3) 添加此代码,并尝试从您的子类别ViewDidLoad 方法调用[self dumpWindow: @"VDL"]。每当检查我的 View 结构是否正确时,我发现它非常有用。

- (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];

关于iphone - TableView 被标题栏遮挡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6324925/

相关文章:

iphone - 如何使用分页加载我的表格 View ?

iphone - UIView左右阴影

ios - removeConstraint() 不删除约束

iphone - IOS 4.3 UINavigationBar tintColor 泄漏

ios4 - UIImagePickerController : ignoring request to take picture; camera is not yet ready

objective-c - 如何从 UIColor 对象中获取红绿蓝 (RGB) 和 alpha?

iphone - 无法仅旋转一个 View

ios - 如何从 Pan 手势触发 Segue?

ios - 您可以使用 OS x 服务器机器人将二进制文件上传到 iTunes connect 吗?

iphone - 验证具有特殊字符的文本字段