我已经使用链接http://www.devx.com/wireless/Article/43374实现了按字母顺序排列的部分标题
它很好用。
我用这个逻辑来获取第一个字符作为索引
// To implement indexes and section headers
contactsArray = [[NSMutableArray alloc] init];
for(int i=0; i< tableViewArray.count ; i++)
{
Contact *contact = [tableViewArray objectAtIndex:i];
[contactsArray addObject:contact.name];
}
contactIndex = [[NSMutableArray alloc] init];
for (int i=0; i<[contactsArray count]; i++){
//---get the first char of each contactName---
char alphabet = [[[contactsArray objectAtIndex:i] uppercaseString] characterAtIndex:0];
NSString *firstChar = [NSString stringWithFormat:@"%C", alphabet];
//---add each letter to the index array---
if (![contactIndex containsObject:firstChar])
{
[contactIndex addObject:firstChar];
}
}
但如果是联系人,它会返回1,2,3...
But need to display # instead of all numaerical values headers