兩種讓tableview返回頂部的方法


1、

 [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:_currentRow inSection:0] animated:YES  scrollPosition:UITableViewScrollPositionMiddle];

 首先使用selectRowAtIndexes: 選擇行數,滾動的話tableview的superview時scrollview,scrollview可以滾動到某個position 那么就要計算這個position position = table row height * index,就得到滾動的位置了。

UITableViewCell自動滾動到頂部
 
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
 
2、繼承自scrollview的方法

[self.tableView setContentOffset:CGPointMake(0,0) animated:YES];


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM