UITableView 滾動到指定行cell

1.滾動到指定的cell

設置需要滾動到的cell的NSIndexPath

[NSIndexPath indexPathForRow: inSection:]

滾動到指定cell

[self.tableview selectRowAtIndexPath:[NSIndexPath indexPathForRow:arc4random_uniform(29) inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];



2.與1類似的方法

[self.tableview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:temp inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];

3.滾動到最近選中的cell(選中的cell消失在屏幕中,觸發事件可以滾動到選中的cell)

[self.tableview scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:YES];


1,2,3用到的枚舉

typedef NS_ENUM(NSInteger, UITableViewScrollPosition) {
    UITableViewScrollPositionNone,
    UITableViewScrollPositionTop,    
    UITableViewScrollPositionMiddle,   
    UITableViewScrollPositionBottom
};




發佈了203 篇原創文章 · 獲贊 44 · 訪問量 49萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章