开发者

The # symbol in UITableView index

I have searched high and low for the answer to this. In the iPhone Phone app on the Contacts tab there is a little magnifying glass symbol for search and a # symbol for the number of 开发者_JAVA百科rows in the contacts table view.

I have implemented the search symbol ok but my # gets sorted to the top of the index. Does anyone know a way to get it to get sorted to the bottom of the index.

Ive been trying for hours and no luck so far. Any help/suggestions really appreciated. Thanks for your time.


Implement this into your codes:

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


implement this in your TableViewDataSource

- (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];
}

likewise use this for your headings:

- (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 @"";
 }
}

Then just arrange your data accordingly. I would use a 2-dimensional array with the outer being the section and the inner being the row in that section. Then you can sort the inner arrays and manage the outer arrays yourself.

Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜