2013-07-29 4 views
-1

인덱싱 된 테이블을 만들고 싶습니다.인덱싱 된 테이블의 한 섹션 만

-(void)awakeFromNib 
{ 
self.heroes = [NSArray arrayWithObjects: @"Aaaa",@"Abbbbb",@"Bbbbb",@"Nnnnn",@"Pppp",@"Xxxx",@"Zzzzz", nil]; 
} 



- (NSArray *)sortedArrayFromArray:(NSArray *)array collationStringSelector:(SEL)selector{ 
return [NSArray arrayWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", nil]; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] objectAtIndex: section]; 
} 

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { 
return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]; 
} 

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { 
return [[UILocalizedIndexedCollation currentCollation] sectionForSectionIndexTitleAtIndex:index]; 
} 

그러나 앱이 시작되면 "A"라는 색인이 하나만 있습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

(배열 표시 제대로)

감사합니다!

+0

이 방법이 있습니까? - (NSInteger) numberOfSectionsInTableView : (UITableView *) tableView – Sauvage

+0

자세한 예제가 있습니다. http://www.iphonedevcentral.com/indexed-uitableview-tutorial/ – Sauvage

답변

0

당신은 ("A"또는 "B"등의 말은 매우 신중하게 실제로 하나 개의 섹션에서해야합니다 얼마나 많은 행을 알려줍니다 것을 구현해야합니다이 경우 numberOfRowsInSection

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return [[[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]count]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [_heroes count]/*do according to your need*/; 
} 

을 보이는 몇 가지 방법을 구현하지 않은).

보다 효과가있을 수 있습니다.

관련 문제