2011-02-17 103 views
0

我已經搜索了高和低的答案。在「聯繫人」選項卡上的iPhone Phone應用程序中,有一個用於搜索的小號放大鏡符號,而在聯繫人表格視圖中有一行符號表示行數。UITableView索引中的#符號

我已經實現了搜索符號ok,但是我的#被分類到索引的頂部。有沒有人知道一種方法讓它得到排序到索引的底部。

我已經嘗試了好幾個小時,至今沒有運氣。任何幫助/建議真的很感激。謝謝你的時間。在TableViewDataSource

回答

0

實現這個

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ 
return [NSArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",@"#",nil]; 
} 

同樣使用此爲您的標題:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ 
switch(section){ 
    case 0: 
    return @"A"; 
    case 1: 
    return @"B"; 
    ... (all the way through the alphabet) 
    case 26: 
    return @"#"; 
    default: 
    return @""; 
} 
} 

然後,只需相應地安排你的數據。我將使用一個二維數組,其中外部是部分,內部是該部分中的行。然後你可以對內部數組進行排序並自己管理外部數組。

希望這會有所幫助!

1

落實到你的代碼是:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ 
    return [[NSArray arrayWithObject:UITableViewIndexSearch] arrayByAddingObjectsFromArray: 
     [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]]; 
}