简体   繁体   中英

headerViewForSection isn't called

I created a new Storyboard app, created an IBOutlet for my table, implemented the two table delegates.

@interface FirstViewController () <UITableViewDelegate,UITableViewDataSource>.

I also implemented the optional selector, "headerViewForSection":

- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section
{
    NSLog(@"called");
    //UITableViewHeaderFooterView* header =[self.testTable headerViewForSection:0];
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
    label.text = @"toast";
    label.font = [UIFont fontWithName:@"Arial" size:6];
    //[header addSubview:label];
    return label;
}

unfortunately, I never get a "called" in the console. I also tried to call this manually, but no success on that one.

Why isn't the function get called?

PS, I added that in the constructor:

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    _testTable.delegate = self;
    _testTable.dataSource = self;
}

so I specified the delegate, I have no why why it's not working.

That method is part of UITableView and is an internal method that the UIViewController doesn't need to go anywhere near.

I believe what you are looking for is the method...

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

which is part of UITableViewDelegate .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM