咱們使用表格控件顯示1-1000,因爲表格太長,咱們可能會參考電話本的索引功能,在右邊顯示1,100,200,300,400,...,1000,這樣用戶點擊500,就能快速顯示500.函數
也就是設置 動畫
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView 函數spa
和orm
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index 函數索引
但咱們點擊第一個索引的時候,有時候會出現空白,表格滾動屏幕底部隱藏起來了,觸摸一下屏幕,表格又出來了,解決辦法就是判斷若是是第一個索引,不要使用動畫效果it
NSIndexPath *indexPath = nil;io
if (iIndex < 1) { //第一個索引不能用動畫效果table
indexPath = [NSIndexPath indexPathForRow:0 inSection:0];scroll
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTopanimated:NO];im
}else {
indexPath = [NSIndexPath indexPathForRow:iIndex-1 inSection:0];
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTopanimated:YES];
}