UILocalizedIndexedCollationアドレスブックのグループ化の並べ替え
Uilocalizedindexedcollation Address Book Grouping Sort
UILocalizedIndexedCollationは、アルファベット順にソートされた配列のインデックスを再構築できます。
LCIndexTool.h
#define kToolsIndexAryKey @'LCIndexAryKey' //Index #define kToolsGroupAryKey @'LCGroupAryKey' //The sorted group
/** Sort array @param mArray array to be sorted @param proretyName Attributes in the array that need to be sorted @return sorted index and gourpAry dictionary form kToolsIndexAryKey kToolsGroupAryKey */ + (NSDictionary *)sortedArrayWithChineseObject:(NSMutableArray *)mArray withPropertyNameSEL:(SEL)nameSEL
proretyNameは、次のような属性名です。
個人クラス属性:名前年齢phoneNumber
名前の最初の文字に従ってグループを並べ替え、@ selector(name)を渡す必要があります
LCIndexTool.m
/ / Array sort + (NSDictionary *)sortedArrayWithChineseObject:(NSMutableArray *)mArray withPropertyNameSEL:(SEL)nameSEL { UILocalizedIndexedCollation *indexCollation = [UILocalizedIndexedCollation currentCollation] NSInteger index, sectionTitlesCount = [[indexCollation sectionTitles] count] NSMutableArray *suoYinArr = [[NSMutableArray alloc] initWithArray:[indexCollation sectionTitles]] / / Temporary data, store the userObjs array data corresponding to the section NSMutableArray *newSectionsArray = [[NSMutableArray alloc] initWithCapacity:sectionTitlesCount] / / Set the sections array initialization: the element contains empty data of userObjs data for (index = 0 index 0 i -- ) { NSInteger index = [willDeleteAry[i - 1] integerValue] [newSectionsArray removeObjectAtIndex:index] [suoYinArr removeObjectAtIndex:index] } / / The dictionary stores the index and data after sorting NSDictionary *dict = @{kToolsGroupAryKey:newSectionsArray,kToolsIndexAryKey:suoYinArr} return dict }
転載:https://www.jianshu.com/p/82e63896c59a