首页 文章

由Titlebar阻挡的TableView

提问于
浏览
0

我正在构建我的第一个基本选项卡式应用程序,其中一个视图作为导航控制器将显示一个视图控制器 .

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

当tableviewcontroller的另一个实例被加载并推送到navigationcontroller的堆栈时,该表被 Headers 栏阻塞: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的第一个选项卡 .

3 回答

  • 0

    两个有趣的事情:它测量20像素(状态栏的大小)和你的行“nextCategoryController.title = ...”似乎没有做任何事情 . 所以...

    1)我假设你没有使用 setStatusBarHidden

    2)看起来navController的东西不起作用 . 你能从appDelegate中提供创建tabBar和NavController的代码吗?

    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: %@ %@ %@ %@", (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];
    
  • 4

    检查KHCategoryTableViewController视图的autoResizingMask .

    iPhone开发中心的UINavigationController概述说:

    注意:由于自定义视图的可用空间量可能不同(取决于其他导航视图的大小),因此应将自定义视图的autoresizingMask属性设置为具有灵活的宽度和高度 . 在显示视图之前,导航控制器会自动定位并调整大小以适应可用空间 .

  • 0

    当我针对iOS 4.3而不是iOS 5构建时,此问题已得到解决 .

相关问题