iOS 重新整理tableview方法

來源:互聯網
上載者:User

標籤:

重新整理UITableView

方法:[self.tableView reloadData];

reloadData是重新整理整個UITableView,有時候,我們可能需要局部重新整理。比如:只重新整理一個cell、只重新整理一個section等等。這個時候在調用reloadData方法,雖然使用者看不出來,但是有些浪費資源。

重新整理局部cell

方法:NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];

這樣就可以很方便的重新整理第一個section的第一個cell。雖然看起來代碼多了,但是確實比較節省資源。盡量少的重新整理,也是UITableView的一種最佳化。

 

局部重新整理section

NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:0];

[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];

上面這段代碼是重新整理第0個section。

重新整理動畫

重新整理UITableView還有幾個動畫:

      typedef NS_ENUM(NSInteger, UITableViewRowAnimation) {

            UITableViewRowAnimationFade,   //淡入淡出

            UITableViewRowAnimationRight,  //從右滑入         // slide in from right (or out to right)

            UITableViewRowAnimationLeft,   //從左滑入

            UITableViewRowAnimationTop,        //從上滑入

            UITableViewRowAnimationBottom,    //從下滑入

            UITableViewRowAnimationNone,            // available in iOS 3.0

            UITableViewRowAnimationMiddle,          // available in iOS 3.2.  attempts to keep cell centered in the space it will/did occupy

            UITableViewRowAnimationAutomatic = 100  // available in iOS 5.0.  chooses an appropriate animation style for you

        };

 

iOS 重新整理tableview方法

聯繫我們

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