2011-12-21 59 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,也不會被調用。