iOS tableView在應用中一些技巧

來源:互聯網
上載者:User

標籤:

1.去掉tableView的分割線
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

2.點擊tableView時去掉灰色效果
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]

3. 讓tableView滾動到最頂部
[self.tableView setContentOffset:CGPointMake(0,0) animated:YES];

4. 中讓tableView重新整理某一行資料
NSIndexPath * idxPath = [NSIndexPath indexPathForRow:<#(NSInteger)#> inSection:<#(NSInteger)#>];

[self.taleView reloadPowAtIndexPaths:@[idxPath] withRowAnimation:UITableViewRowActionStyleDefault];

5.設定tableView的行不允許被選中
     1>self.tableview.allowsSelection=NO;

     2>self.tableView.userInteractionEnabled =NO;(這種情況對於cell較少的好使,但是當cell較多時不能用它,因為他會把tableView給禁止掉,導致不能滑動)

     3>直接加蒙版,設定view。

6. 中讓tableView的最後一行滾動到最上面
NSIndexPath * idxPath = [NSIndexPath indexPathForRow:<#(NSInteger)#> inSection:<#(NSInteger)#>];

[self.taleView scrollToRowAtIndexPaths:idxPath atScrollPosition:UITableViewScrollPositionTop annimated:YES];

7.總結tableview的重新整理

      1>- (void)reloadData;重新整理整個表格。

      2>- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 重新整理指定的分組和行。

     3.>- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation 重新整理指定的分組。

     4>- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;刪除時重新整理指定的行資料。

     5>- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;添加時重新整理指定的行資料。

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.