IOS UITableView quick scrolling (index implementation)

Source: Internet
Author: User

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:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.