IOS UITableView quick scrolling (index implementation)
Idea: If UITableView loads too much data at a time, it is required to slide the base multiple times. To quickly slide through indexes, add 20 null points to the index. When you slide to the rightmost side, the index box shows that the RowIndex pointing to the UITableView corresponding to the index points to achieve quick scrolling. This method has a defect: the scroll bar is overwritten when moving normally.
Main Code:
// Obtain data-(void) getTableData {dispatch_async (dispatch_get_global_queue (queue, 0), ^ {dispatch_async (dispatch_get_main_queue (), ^ {// obtain database data self. listArray = [[ReportLogic sharedInstance] getProductByCategory]; if ([self. listArray count] = 0) {[GlobalApplication Alert: @ prompt: @ No data];} else {// index directory, 20 blank points NSMutableArray * stArray = [[NSMutableArray alloc] init]; self. sectionTitles = stArray; [stArray release]; for (int I = 0; I <20; I ++) {NSString * index = @; [self. sectionTitles insertObject: index atIndex: I] ;}// refresh data [self. fmTableView reloadData] ;}) ;}# pragma mark index // Number of partitions-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return 1 ;} // index directory-(NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView {return self. sectionTitles;} // when sliding, click the directory-(NSInteger) tableView :( UITableView *) tableView sectionForSectionIndexTitle :( NSString *) title atIndex :( NSInteger) index {// modify the index focus to UITableView's RowIndex, header and tail, and intermediate value if (index = 0) {index = 1;} else if (index = self. sectionTitles. count-1) {index = self. listArray. count-1;} else index = round (index * self. listArray. count/20); [self. fmTableView scrollToRowAtIndexPath: [NSIndexPath indexPathForRow: index inSection: 0] atScrollPosition: UITableViewScrollPositionBottom animated: YES]; return index ;}
Effect: