iOS UITableView 快速滾動(索引方式實現)

來源:互聯網
上載者:User

iOS UITableView 快速滾動(索引方式實現)

 

思路:UITableView一次性載入資料過多時,需要滑動多次觸底。想通過索引實現快速滑動,索引中載入20個空點。使用者在最右端滑動時,索引框顯示,當觸及索引點時指向其想對應的UITableView的RowIndex來實現快速滾動。這方法有缺陷:普通滑動時捲軸被遮蓋了。

主要代碼:

 

//擷取資料-(void)getTableData{        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{        dispatch_async(dispatch_get_main_queue(), ^{            // 擷取資料庫資料            self.listArray = [[ReportLogic sharedInstance] getProductByCategory];            if ([self.listArray count] == 0) {                [GlobalApplication Alert:@提示 :@暫無資料];            }else{                // 索引目錄,20個空點                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];                }            }            // 資料重新整理            [self.fmTableView reloadData];        });    });}#pragma mark index// 分區數-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{      return 1;}// 索引目錄-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{    return self.sectionTitles;}// 滑動時點擊目錄-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{         // 修正索引焦點為UITableView的RowIndex,頭尾和中間值    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;} 

效果:

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.