如何在视图出现之前滚动到 iPhone 上 UITableView 的底部 [英] How to scroll to the bottom of a UITableView on the iPhone before the view appears

查看:24
本文介绍了如何在视图出现之前滚动到 iPhone 上 UITableView 的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableView 填充了可变高度的单元格.当视图被推入视图时,我希望表格滚动到底部.

I have a UITableView that is populated with cells of a variable height. I would like the table to scroll to the bottom when the view is pushed into view.

我目前有以下功能

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[log count]-1 inSection:0];
[self.table scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

log 是一个可变数组,其中包含构成每个单元格内容的对象.

log is a mutable array containing the objects that make up the content of each cell.

上面的代码在 viewDidAppear 中工作正常,但是这有一个不幸的副作用,即当视图第一次出现时显示表格的顶部,然后跳到底部.如果 table view 可以在它出现之前滚动到底部,我会更喜欢它.

The above code works fine in viewDidAppear however this has the unfortunate side effect of displaying the top of the table when the view first appears and then jumping to the bottom. I would prefer it if the table view could be scrolled to the bottom before it appears.

我在 viewWillAppearviewDidLoad 中尝试了滚动,但在这两种情况下,数据尚未加载到表中,并且都抛出异常.

I tried the scroll in viewWillAppear and viewDidLoad but in both cases the data has not been loaded into the table yet and both throw an exception.

任何指导都将不胜感激,即使只是告诉我我所拥有的一切都是可能的.

Any guidance would be much appreciated, even if it's just a case of telling me what I have is all that is possible.

推荐答案

我相信调用

 tableView.setContentOffset(CGPoint(x: 0, y: CGFloat.greatestFiniteMagnitude), animated: false)

会做你想做的事.

这篇关于如何在视图出现之前滚动到 iPhone 上 UITableView 的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆