2011-12-21 29 views
0

我正在设置一个带有部分的UITableViewnumberOfSectionsInTableView:方法被调用正确,并返回正确的结果(在我的情况3),但titleForHeaderInSection根本没有被调用,并且结果tableview包含行但没有部分。titleForHeaderInSection在实现UITableViewDataSource协议时未被调用

有没有办法确保这个方法被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; 
} 

回答

2

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