。1 2 3。 // イニシャルパケット配列をソート 4。 5 - (NSMutableArrayの*)sortObjectsAccordingToInitialWith:(にNSArray * ){ARR 。6 。7 。8 。9 // UILocalizedIndexedCollation初期化する 10 。11 UILocalizedIndexedCollation照合* = [UILocalizedIndexedCollation currentCollation]; 12である 13ことである 14 15 / / ここで、照合インデックス番号を星27(26の文字および#)である 16 17。 NSInteger sectionTitlesCount = ; [照合sectionTitles] COUNT] 18である 19。 //データの先頭に[C @、データ列の先頭に[B] @、[]データ配列Aの先頭の[@得られたデータを格納するために使用される配列、我々は最終的にフォーム@を取得する必要があり、データ・モデルを初期化NewSectionsArrayアレイ]、@ ... [データアレイ位(他の)開始時] 20は 21れる NSMutableArrayのnewSectionsArray * = [[NSMutableArrayのALLOC] initWithCapacity:sectionTitlesCount]; 22は 23である 24 25 // 空のアレイ27をnewSectionsArray加え初期化 26である 27 用(インデックスNSInteger = 0 ;インデックス<sectionTitlesCount;インデックス++ ){ 28 29 NSMutableArrayのアレイ* = [[NSMutableArrayのアロケーション]のinit]; 30 31である } 32 33は 34である 35 // に割り当てられた名前の下で各セクション 36 37 のために(* ContactsUserModelのusermodel で_aryUser){ 38である 39 // このような「林」として取得した名前の属性の値は、最初の文字は、ランク11でL、A〜Zの位置(最初のビットが0です)、 11 sectionNumber 40 41れる // に対応する属性名の実名モデル 42は 43である 44である 45 NSInteger sectionNumber = [照合sectionForObject:usermodelのcollationStringSelector:@selector(実名)]; 46である 47 // P添加newSectionsArrayにおける"リンデン"の名前11のアレイ 48 49 * sectionNames = NSMutableArrayのnewSectionsArray [sectionNumber]; 50 51であります 【sectionNamesのaddObjectは:usermodel]; 52は 53である 54である 55 56れている 57で のNSLog(@ " sectionNames ===%の@ " 、sectionNames); 58 59 60 61である } 62が 63である 64 65 のNSLog(@ " newSectionsArray ==%の@ " 、newSectionsArray) ; 66 67 68 69 70 71れる // 属性名に応じて、各セクションの配列をソート 72 73である ため(インデックスNSInteger = 0 ;インデックス<sectionTitlesCountインデックス++ ){ 74 75 NSMutableArrayの* personArrayForSection = newSectionsArray [インデックス]。 76 77 にNSArray * sortedPersonArrayForSection = [照合sortedArrayFromArray:personArrayForSection collationStringSelector:@selector(名)]。 78 79 newSectionsArray [インデックス] = sortedPersonArrayForSection。 80 81 } 82 83 のNSLog(@ " newSectionsArray ==%の@ " 、newSectionsArray)。 84 85 86 87 // // 删除空的数组 88 89 NSMutableArrayの* finalArr = [NSMutableArrayの新しいです]。 90 91 _sectionTitles = [NSMutableArrayのアレイ]; 92 93 [_sectionTitlesのaddObject:"@ 部门" ]; 94 95 96 97 98 99 用(NSIntegerインデックス= 0、インデックス<sectionTitlesCount;インデックス++ ){ 100 101 102 103 場合(。!((NSMutableArrayの*)は(newSectionsArrayが[インデックス]))は、カウント= 0 ){ 104 105 [finalArrのaddObject :newSectionsArray [インデックス]。 106 107 [self.sectionTitlesのaddObject:[照合sectionTitles] objectAtIndex:インデックス]]; 108 109 110 111 112 113 } 114 115 } 1 16 117 1 18 119 リターン finalArr; // ない配列値を削除しない 120 121 122 123 124 125 / / newSectionsArrayを返す。 126 127 128 129 } 130 131は、 132 134 135件 の#pragmaマークSectionTitles 136 137- (NSStringの*)のtableView:(のUITableView * )のtableView titleForHeaderInSection:(NSInteger)セクション 138 139 { 140 141 戻りself.sectionTitles [部]。 142 143 } 144 145 146 147 - (にNSArray *)sectionIndexTitlesForTableView:(のUITableView * )のtableView 148 149 { 150 151 戻りself.sectionTitles。 152 153 }