UItableview scrollToRowAtIndexPath未正确显示最后一行 [英] UItableview scrollToRowAtIndexPath not displaying last row correctly

查看:119
本文介绍了UItableview scrollToRowAtIndexPath未正确显示最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有动态单元格高度的自定义单元格的tableview,具体取决于单元格内容。

I have a tableview with custom cells with dynamic cell heights depending on the cell content.

当我在viewDidLoad中以编程方式询问时,我的问题如下,滚动到它工作的给定位置,除了最后一行。有时行出现但不完整,有时甚至不出现。在这两种情况下,我都必须手动滚动才能看到该行。

My problem is the following, when I ask, programmatically, in the viewDidLoad, to scroll to a given position it works, except for the last row. Sometime the row appears but not fully, and sometimes it even does not appear. In both cases I have to scroll manually to see the row.

以下是代码:

[self.tableView reloadData];

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:aRow inSection:aSection];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES ];

这是iOS的错误吗?任何解决方法?

Is this a bug of iOS ? any workaround ?

推荐答案

到目前为止我已经知道了,

As so far i came to know that,

屏幕上显示的视图之前的所有操作都在 viewDidLoad 中初始化了所有UI对象,可以在此方法中分配和初始化数据对象。

All the operations used to before the view is shown on the screen are initialized in the viewDidLoad all the UI objects, data objects can be allocated and initialized in this method.

所有操作数据修改,对视图的UI修改需要在 viewDidAppear 中完成。或者甚至可以在 viewWillAppear 中完成一些操作。

All the operations data modifications, UI modifications made to view need to be done in viewDidAppear. Or even some operations can be done in viewWillAppear.

所以对于你的问题,表格加载后,必须完成UITableView 滚动操作。显示在屏幕上,即 viewDidAppear

So for your issue, the UITableView scrolling must be done after the table is loaded on & shown on screen i.e., in viewDidAppear.

另请注意 viewDidAppear &每次向用户显示视图时都会调用 viewWillAppear ,因此,如果只想为第一个实例滚动表,则可以在标题中指示实例。

Also note that viewDidAppear & viewWillAppear will be called each time view is shown to user, so if you want to scroll the table only for the first instance you can have a flag in your header indicating the instance.

这篇关于UItableview scrollToRowAtIndexPath未正确显示最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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