How to Start UITableView on the Last Cell?

前端 未结 8 1261
囚心锁ツ
囚心锁ツ 2020-11-30 01:43

In Apple\'s Messages app, when you click a correspondent\'s name and switch to the table view of the conversation (with balloons for each message), the table appears scrolle

8条回答
  •  萌比男神i
    2020-11-30 02:28

    Note for scrolling to the bottom row, the section needs to be last section not 0 (first section):

    int lastSection = [self.myTableView numberOfSections] -1;
    if (lastSection < 0) return;
    
    int lastRow = [self.myTableView numberOfRowsInSection:lastSection] - 1;
    if (lastRow < 0) return;  
    NSIndexPath* ip = [NSIndexPath indexPathForRow:lastRow inSection:lastSection];
    
     [self.myTableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionTop animated:YES];
    

提交回复
热议问题