Some Gap remains between Table Top and Table Head

2019-02-20 11:09发布

Edit: It works fine, But still when the table get Loads Some gap remains between table top and table header abt 30 pxcls(or 1 row) ..?

Please help....

I am scrolling it works fine. All the table rows are scrolling and table header is fixed. But when I scroll to end of the table it looses its property of fix. I mean is boundry scrolling. I want to freeze it absolutely. At the boundary condition it looses the top position of the table and slides about 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;
}

1条回答
孤傲高冷的网名
2楼-- · 2019-02-20 11:55

If I understand your question correctly, it sounds like you just need the table not to bounce. If that's the case, all you need to do is set yourTable.bounces = NO; in your viewDidLoad function. Either that or uncheck the "Bounces" option in the NIB if you used one to layout your table.

Here's how to fix the problem you mentioned in your edit... You need to replace the following references to tableView.headerView with references to a new view that's not being passed into the delegate method.

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

I tried it and it did the trick for me. Hope that helps.

查看更多
登录 后发表回答