How to use UITableViewHeaderFooterView?

后端 未结 9 2057
傲寒
傲寒 2020-12-23 02:12

Hi I want to use UITableHeaderFooterView in my app and i am doing this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional          


        
9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 02:27

    Here is a "quick-and-dirty" way to get this going. It will make a small blue label in the header. I've confirmed that this renders OK in iOS 6 and iOS 7.

    in your UITableViewDelegate:

     -(void)viewDidLoad
    {
    ...
        [self.table registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"Header"];
    ...
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return 34.;
    }
    
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        UITableViewHeaderFooterView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"Header"];
    
        UILabel *leftlabel = [[UILabel alloc] initWithFrame:CGRectMake(0., 0., 400., 34.)];
        [leftlabel setBackgroundColor:[UIColor blueColor]];
    
        [header.contentView addSubview:leftlabel];
        return header;
    }
    

提交回复
热议问题