iOS UItableview scrollToRowAtIndexPath不再工作 [英] iOS UItableview scrollToRowAtIndexPath not working anymore

查看:1122
本文介绍了iOS UItableview scrollToRowAtIndexPath不再工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早上我刚刚安装了包含iOS 6的新Xcode。

This morning I just installed new Xcode which includes iOS 6.

我有一个表格视图,其中包含一个包含章节和行的plist文件。章节定义了部分。

I have a table view loaded with a plist file containing chapters and lines. Chapters define the sections.

用户选择章节和行,并且tableview会自动滚动到正确的位置(在viewDidLoad中)。

The user selects chapter and line and the tableview is automatically scrolled to the correct position (in the viewDidLoad).

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

这在iOS5模拟器中效果很好。

this works just great in iOS5 simulator.

在iOS 6模拟器中尝试此操作不会执行滚动。我没有错。我已经检查过,linePos和chapterPos收到了正确的值但是没有执行滚动。

Trying this in the iOS 6 simulator the scroll is not performed. I get no errors. I have checked, linePos and chapterPos receive correct values but the scroll is not performed.

任何想法为什么?

推荐答案

对于iOS的最新版本,请阅读Fyodor Volchyok的回答。请注意,它并未标记为已接受的答案,因为当时问题是第一次提出的( 2012年9月),目前的答案是工作解决方案。
更新版本的iOS也遇到了同样的问题,现在由Fyodor Volchyok的答案解决了,所以你应该在那一刻给他答案+1。

For recent versions of iOS, please read Fyodor Volchyok's answer. Note that it's not marked as the accepted answer simply because at the time the question was first asked (Sept. 2012), the current answer was the working solution. More recent versions of iOS also got the same problem which is now solved by Fyodor Volchyok's answer, so you should +1 his answer at that moment.

我找到了答案。我必须先在tableview中重新加载数据

I found the answer. I have to first reload the data in the tableview

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:linePos inSection:chapterPos];

[self.tableView reloadData];

[self.tableView scrollToRowAtIndexPath:indexPath 
    atScrollPosition:UITableViewScrollPositionTop animated:YES];

即使我找到答案,我也不知道为什么它在iOS5中工作而不在iOS6中工作。

Even though I found the answer I don't know why it is working in iOS5 and not in iOS6.

编辑

也许我应该补充说即使它正常工作,我在显示最后一行时仍遇到问题并发布了一个问题

Perhaps I should add that even though it was working, I was still having a problem in displaying the last row and posted a question for that

UItableview scrollToRowAtIndexPath没有正确显示最后一行

由于@Raj也要求它,我应该说我在 viewDidLoad 中触发了它。要纠正最后一行无法正确显示的问题,我必须将其放入 viewDidAppear

As @Raj also asked for it, I should say that I was triggering that in the viewDidLoad. To correct the problem of the last row not displaying correctly I had to put it in the viewDidAppear.

这篇关于iOS UItableview scrollToRowAtIndexPath不再工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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