在实现UITableViewDataSource协议时未调用titleForHeaderInSection

时间:2011-12-21 03:18:11

标签: objective-c ios uitableview

我正在设置UITableView部分。正确调用numberOfSectionsInTableView:方法并返回正确的结果(在我的情况下为3)但是根本没有调用titleForHeaderInSection,结果的tableview包含行但没有节。

有没有办法确保tableview调用此方法?

以下是实施:

- (NSString *) titleForHeaderInSection:(NSInteger)section 
{        
    NSString *sectionHeader = nil;

    if (section == 0) 
    {
        sectionHeader = @"Alpha";
    }
    if (section == 1) 
    {
        sectionHeader = @"Beta";
    }
    if (section == 2) 
    {
        sectionHeader = @"Gamma";
    }

    NSLog(@"%@", sectionHeader);

    return sectionHeader;
}

1 个答案:

答案 0 :(得分:2)

方法签名为- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section您的方法缺少第一个参数tableView,并且不会被调用。