ios學習:UITableview二(下拉重新整理)

來源:互聯網
上載者:User

 

  1 /*  2  實現tableview的下拉重新整理  3  tableview滑動就會觸發這個方法?  4  */  5 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath  6 {  7     //當tableview下拉到最後一行的時候才觸發  8     if (indexPath.row == self.m_data.count - 1) {  9          10         //定義一個UIView 11         UIView *footSpinnerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 60.0f)]; 12          13         //頂一個有重新整理表徵圖的view 14         UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(130.0f, 0.0f, 60.0f, 60.0f)]; 15         activity.color = [UIColor redColor]; 16         [activity startAnimating];//啟動有重新整理表徵圖的view 17          18         footSpinnerView.backgroundColor = [UIColor grayColor]; 19         [footSpinnerView addSubview:activity]; 20          21         //設定footerview 22         self.myTableView.tableFooterView = footSpinnerView; 23          24      //   self.myTableView.tableHeaderView = footSpinnerView; 25          26         dispatch_queue_t queue = dispatch_queue_create("my queue", nil); 27          28         //在後台線程添加資料 29         dispatch_async(queue, ^(void){ 30              31             [self.m_data addObject:@"1000"]; 32             [self.m_data addObject:@"1001"]; 33             [self.m_data addObject:@"1002"]; 34             [self.m_data addObject:@"1003"]; 35             [self.m_data addObject:@"1004"]; 36              37         }); 38          39         //添加完資料就重新載入資料 40         dispatch_async(queue, ^(void) { 41              42             sleep(2); 43             dispatch_sync(dispatch_get_main_queue(), ^(void){ 44                  45                 [self.myTableView reloadData]; 46             }); 47         }); 48          49        // [self.myTableView reloadData]; 50         dispatch_release(queue); 51         [footSpinnerView release]; 52         [activity release]; 53     } 54 //   else if (indexPath.row == 0) { 55 //         56 //        UIView *footSpinnerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 60.0f)]; 57 //        UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(130.0f, 0.0f, 60.0f, 60.0f)]; 58 //        activity.color = [UIColor redColor]; 59 //        [activity startAnimating]; 60 //         61 //        footSpinnerView.backgroundColor = [UIColor grayColor]; 62 //        [footSpinnerView addSubview:activity]; 63 //         64 //     //   self.myTableView.tableFooterView = footSpinnerView; 65 //         66 //        self.myTableView.tableHeaderView = footSpinnerView; 67 //         68 //        dispatch_queue_t queue = dispatch_queue_create("my queue", nil); 69 //         70 //        dispatch_async(queue, ^(void){ 71 //             72 //            [self.m_data insertObject:@"1000" atIndex:0]; 73 ////            [self.m_data addObject:@"1001"]; 74 ////            [self.m_data addObject:@"1002"]; 75 ////            [self.m_data addObject:@"1003"]; 76 ////            [self.m_data addObject:@"1004"]; 77 //         //   [self.m_data insertObject:[NSArray arrayWithObject:@"01"] atIndex:0]; 78 //             79 //        }); 80 //         81 //        dispatch_async(queue, ^(void) { 82 //             83 //            sleep(2); 84 //            dispatch_sync(dispatch_get_main_queue(), ^(void){ 85 //                 86 //                [self.myTableView reloadData]; 87 //                [self.myTableView scrollToRowAtIndexPath:[indexPath initWithIndex:3] atScrollPosition:UITableViewScrollPositionNone animated:YES]; 88 //           }); 89 //        }); 90 //         91 // 92 //       dispatch_release(queue); 93 //        [footSpinnerView release]; 94 //        [activity release]; 95 //    } 96  97     //如果不是最後一行,則把footerview和headerview都設為nil 98     else 99     {100         self.myTableView.tableFooterView = nil;101         self.myTableView.tableHeaderView = nil;102     }103 }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.