2012-02-20 11 views
1

すべて、sectionIndexTitlesForTableViewのインデックスを正しく設定しています

セクションインデックス(インデックス)をテーブルビューに追加しても問題ありません。 「K」をタップすると、セクション「K」に移動します。私は現在セクションインデックスに虫めがねを追加しようとしています。もちろん、セクションインデックスはセクションに完全にはマップされません。なぜなら、インデックスは現在オフラインになっているからです。 "A"はインデックス0に使用されていましたが、現在虫眼鏡はインデックス0になっていますので、今では1つのインデックスですべて消えています。あなたは "J"をタップして "K"などを取得します。誰かが拡大鏡を追加する最良の方法を私に説明できますか?おかげ

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ 

NSMutableArray *indices = [NSMutableArray array]; 

//Add the magnifying glass as the first element in the indices array 
[indices addObject:UITableViewIndexSearch]; 

for(int i = 0; i<sorted.count; i++){ 

    [indices addObject:[sorted objectAtIndex:i]]; 



} 
return indices; 

}

答えて

2

は、私はそれが最初の虫眼鏡を追加し、すべてのキーを追加してインデックスを設定するために、高速列挙を使用して作業しました:A、B、C ... X、Y 、Z ... 1,2、... 8,9

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView 
{ 
    NSMutableArray *indices = 
    [NSMutableArray arrayWithCapacity:[sorted count]+1]; 

    [indices addObject:UITableViewIndexSearch]; 

    for (NSString *item in sorted) 
     [indices addObject:[item substringToIndex:1]]; 


    return indices; 
} 
関連する問題