IOS开发中通讯录的中文首字母的排序参数
来源:爱站网时间:2021-02-25编辑:网友分享
在项目开发中要如何获取手机中的通讯录,还要根据姓名首字母进行匹配,下面爱站技术频道小编一起来介绍IOS开发中通讯录的中文首字母的排序参数,一起参考下面的介绍吧!
在项目开发中要如何获取手机中的通讯录,还要根据姓名首字母进行匹配,下面爱站技术频道小编一起来介绍IOS开发中通讯录的中文首字母的排序参数,一起参考下面的介绍吧!
iOS中获取手机通讯录中的联系人信息:
/*** 加载本地联系人*/
- (void)loadLocalContacts
{
//新建一个通讯录类
ABAddressBookRef addressBooks = nil;
if (DeviceVersion
顺便把索引和tableView dataSource的代理方法也贴一下:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.contacts.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.contacts[section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"contactCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
cell.imageView.image = [UIImage imageNamed:@"default_head"];
cell.textLabel.text = [self.contacts objectAtIndex:indexPath.section][indexPath.row];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [_indexArray objectAtIndex:section];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return _indexArray;
}
//索引列点击事件
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
return index;
}
还有两个很重要的方法:
下面这个方法是[theCollation sectionForObject:p collationStringSelector:@selector(getFirstLetter)]; 是这里的p对象要实现的方法,我这里的p是NSString,你也可以用其他对象例如Person。
NSString *ret = @"";
if (![self canBeConvertedToEncoding: NSASCIIStringEncoding]) {//如果是英语
if ([[self letters] length]>2) {
ret = [[self letters] substringToIndex:1];
}
}
else {
ret = [NSString stringWithFormat:@"%c",[self characterAtIndex:0]];
}
return ret;
}
下面这个方法是NSString得类别方法
- (NSString *)letters{
NSMutableString *letterString = [NSMutableString string];
int len = [self length];
for (int i = 0;i 0) {
oneChar = [temA objectAtIndex:0];
}
}
[letterString appendString:oneChar];
}
return letterString;
}
以上就是爱站技术频道小编为您介绍的IOS开发中通讯录的中文首字母的排序参数,希望可以帮助您找到更多靠谱技巧。
上一篇:IOS城市定位的简单展示
