剛剛在制作字母索引列表時用到了索引的一些知識,整理一下:
1.索引數(shù)與分區(qū)數(shù)相同笼呆,不需要設置,
//返回section的個數(shù)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
2.索引實質上是一個由字符串組成的數(shù)組:
//返回索引數(shù)組
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
//返回數(shù)組中的元素
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
3.索引的響應函數(shù)
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
這個返回值其實感覺有點莫名其妙,不過不要緊偶翅,把它當做無返回值得函數(shù)辜腺,實現(xiàn)你要的效果最后return 0;就好了休建。
當然,如果你要滾動tableView到索引對應的位置的話(本來有自動滾動的功能评疗,但是在你重寫此方法時被覆蓋掉了)测砂,可以用到這個:
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:0 inSection:index];
[self.musicListTableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
return index;