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

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

问题描述

我有一个 UITableView 填充一个可变高度的单元格。



我目前有以下函数

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

log是一个包含组成每个单元格内容的对象的可变数组。



上面的代码在 viewDidAppear 中可以正常工作,但是当视图第一次出现时,这会带来不幸的副作用:显示表的顶部然后跳到底部。如果表视图可以滚动到底部,我会喜欢它。



viewWillAppear viewDidLoad 中,但在这两种情况下,数据尚未加载到表中,并且都抛出异常。



任何指导都会非常感激,即使它只是告诉我我的一切是可能的。

[table setContentOffset:CGPointMake(0,CGFLOAT_MAX)] 会做你想要的。 / p>

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.

I currently have the following function

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

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

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.

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.

解决方案

I believe that calling [table setContentOffset:CGPointMake(0, CGFLOAT_MAX)] will do what you want.

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

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