2012-02-20 248 views
1

全部,为sectionIndexTitlesForTableView正确设置索引

我在我的tableview中添加了段索引(索引),它工作正常。点击“K”,然后转到“K”部分。我现在试图通过把它放到我的索引数组中来将分割图放到分区索引中,当然,分区索引不会干净地映射到分区上,因为索引现在已经关闭了。 “A”曾经是索引0,现在放大镜在索引0处,所以现在全部关闭一个索引。你点击“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; 
}