开发者

How do you scroll to the bottom of a tableView if you don't know how many rows it has?

开发者 https://www.devze.com 2023-03-20 16:39 出处:网络
I know that we can scroll to the bottom of the UITableView in a regular UITableViewController by using:

I know that we can scroll to the bottom of the UITableView in a regular UITableViewController by using:

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPa开发者_开发问答th atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated

Where indexPath can be found by doing a count of how many objects are there in the array of objects. However, in three20.. how do we do the same thing as we don't have the array of objects in the table?


I don't know if there's something that makes three20 different, but this should work in any UITableViewController subclass:

- (void)scrollToBottom {
    NSInteger section = [self.tableView numberOfSections] - 1;
    NSInteger row = [self.tableView numberOfRowsInSection:section] - 1;
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
    [self.tableView scrollToRowAtIndexPath:indexPath 
                          atScrollPosition:UITableViewScrollPositionMiddle 
                                  animated:YES];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号