iOS 8自动单元格高度 - didSelectRowAtIndexPath导致UItableview跳转到顶部 [英] iOS 8 Auto cell height - didSelectRowAtIndexPath causes UItableview to jump to top

查看:154
本文介绍了iOS 8自动单元格高度 - didSelectRowAtIndexPath导致UItableview跳转到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将应用更新到iOS8,并且正在替换我自己的单元格高度计算。我有一堆自定义单元格的tableview。选择后的每个单元格都会将新视图呈现/推送到navigationController。当使用这些单元格填充tableview,并且用户选择靠近表格底部的表格视图时,tableview会在显示新视图之前跳转到右上角。这对用户来说非常分散注意力。我正在尝试使用iOS 8中引入的自定义单元格(在viewDidLoad中):

I'm currently updating an app to iOS8, and am replacing my own cell height calculations. I have a tableview with a bunch of custom cells. Each cell when selected will present/push a new view onto the navigationController. When the tableview is populated with these cells, and the user selects one near the bottom of the table, the tableview jumps to the top right before the new view is presented. This is very distracting to the user. I'm trying using self sizing cells introduced in iOS 8 here (in the viewDidLoad):

self.tableView.estimatedRowHeight = 60.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

以下是选择单元格时的代码

Here's the code for when a cell is selected

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UIViewController *selectedViewController = [[UIStoryboard storyboardWithName:@"Trip" bundle:nil] instantiateViewControllerWithIdentifier:@"TripDetail"];
    DetailViewController *destViewController = (id)selectedViewController;
    [destViewController setData:self.dataStore];

    [self.navigationController pushViewController:selectedViewController animated:YES];
}

有谁知道为什么会这样?我怎么能让它停下来?

Does anyone know why this is happening? And how I can make it stop?

推荐答案

这是一个已知的问题。 tableView调用它的委托来获取行的估计高度,这导致表滚动。

It's a known issue. The tableView is calling its delegate to get an estimated height for the rows, which is causing the table to scroll.

你可以等到它在下次更新中是否已修复或者实现 tableView:estimatedHeightForRowAtIndexPath:(作为现在的解决方法)并返回缓存高度。由于估计值将是实际高度,因此表格不会跳转。

You can wait to see if it's fixed in the next update, or implement tableView:estimatedHeightForRowAtIndexPath: (as a workaround for now) and return a cached height. Since the estimate will be the actual height, the table won't jump.

这篇关于iOS 8自动单元格高度 - didSelectRowAtIndexPath导致UItableview跳转到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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