How to add a footer to the UITableView?

前端 未结 11 1966
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 04:23

I\'me using this code to add a footer to the TableView. It has 20 sections, and each section a few rows. There\'s a titleForHeaderInSection, and sectionForSectionIndexTitle

11条回答
  •  情话喂你
    2020-11-29 04:52

    I know that this is a pretty old question but I've just met same issue. I don't know exactly why but it seems that tableFooterView can be only an instance of UIView (not "kind of" but "is member")... So in my case I've created new UIView object (for example wrapperView) and add my custom subview to it... In your case, chamge your code from:

    CGRect footerRect = CGRectMake(0, 0, 320, 40);
    UILabel *tableFooter = [[UILabel alloc] initWithFrame:footerRect];
    tableFooter.textColor = [UIColor blueColor];
    tableFooter.backgroundColor = [self.theTable backgroundColor];
    tableFooter.opaque = YES;
    tableFooter.font = [UIFont boldSystemFontOfSize:15];
    tableFooter.text = @"test";
    self.theTable.tableFooterView = tableFooter;
    [tableFooter release];
    

    to:

    CGRect footerRect = CGRectMake(0, 0, 320, 40);
    UIView *wrapperView = [[UIView alloc] initWithFrame:footerRect];
    
    UILabel *tableFooter = [[UILabel alloc] initWithFrame:footerRect];
    tableFooter.textColor = [UIColor blueColor];
    tableFooter.backgroundColor = [self.theTable backgroundColor];
    tableFooter.opaque = YES;
    tableFooter.font = [UIFont boldSystemFontOfSize:15];
    tableFooter.text = @"test";
    
    [wrapperView addSubview:tableFooter];
    
    self.theTable.tableFooterView = wrapperView;
    [wrapperView release];
    [tableFooter release];
    

    Hope it helps. It works for me.

提交回复
热议问题