只有当表加载并向下滚动到最后一行时,Table Top和Table Header之间才会保留一些间隙



编辑:它工作得很好,但仍然当表得到负载一些差距仍然在桌面和表头之间约30 pxcls(或1行)..?

请帮…

我正在滚动,它工作得很好。所有的表行都是滚动的,表头是固定的。但当我滚动到表的末尾时它就失去了固定属性。我指的是边界滚动。我要把它完全冷冻起来。在边界条件下,它将失去表的顶部位置,并滑动约20 pxcls。

//Header Format starting
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section     
{
    if (tableView.tableHeaderView) { // header was already created... go away
        return tableView.tableHeaderView;
    }
    CGFloat width = 300.0f;
    CGRect rectArea = CGRectMake(10.0f, 5.0f, width, 25.0);
    tableView.tableHeaderView = [[[UIView alloc] initWithFrame:rectArea] autorelease];
    //UIColor *orange =  [UIColor colorWithRed:(255.0f/255.0f) green:(228.0f/255.0f) blue:0.0f alpha:1.0f];
    [tableView.tableHeaderView setBackgroundColor:[UIColor grayColor]];
    rectArea = CGRectMake(02.0f, 1.0f, width, 20.0);
    UILabel *lbl = [[UILabel alloc] initWithFrame:rectArea];
    lbl.text = NSLocalizedString(@"Bill Total", @"");
    lbl.textAlignment = UITextAlignmentLeft;
    //lbl.font = [UIFont systemFontOfSize:13.0f];
    lbl.font = [UIFont fontWithName:@"Courier New" size:14];
    lbl.font=[UIFont italicSystemFontOfSize:14];
    lbl.textColor = [UIColor blackColor];
    lbl.backgroundColor = [UIColor clearColor];
    lbl.numberOfLines = 2.0f;
    lbl.lineBreakMode = UILineBreakModeWordWrap;
    //[lbl sizeToFit];
    [tableView.tableHeaderView addSubview:lbl];
    [lbl release];
    // self.table.tableHeaderView.layer.cornerRadius = 6.0f;
    return table.tableHeaderView;
}

如果我正确理解你的问题,听起来你只需要表不反弹。如果是这种情况,你所需要做的就是在viewDidLoad函数中设置yourTable.bounces = NO;。或者取消选中NIB中的"Bounces"选项(如果您使用一个来布局您的表)。

这是如何解决你在编辑中提到的问题…你需要替换以下对tableView的引用。headerView,它引用了一个没有被传递到委托方法中的新视图。

    UIView *headerView = [[[UIView alloc] initWithFrame:rectArea] autorelease];
    //...    
    [headerView setBackgroundColor:[UIColor grayColor]];
    //...
    [headerView addSubview:lbl];
    //...
    return headerView;

我试过了,效果很好。

最新更新