How to add a footer to the UITableView?

前端 未结 11 1957
没有蜡笔的小新
没有蜡笔的小新 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:51

    Initially I was just trying the method:

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
    

    but after using this along with:

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
    

    problem was solved. Sample Program-

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
    {
        return 30.0f;
    }
    
    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
    {
        UIView *sampleView = [[UIView alloc] init];
        sampleView.frame = CGRectMake(SCREEN_WIDTH/2, 5, 60, 4);
        sampleView.backgroundColor = [UIColor blackColor];
        return sampleView;
    }
    

    and include UITableViewDelegate protocol.

    @interface TestViewController : UIViewController 
    

提交回复
热议问题