iphone -scrollRectToVisible 问题
这个功能完美,但我想让它成为一次性功能,而不是固定功能。当我用其他数据更改表视图时,数据显示在前一个表视图的索引处。所以我的解决方案是实现下面的代码。当我实现这个时,它可以工作,但是当我向下滚动时,它一直向上滚动,因此几乎不可能进一步向下滚动。知道如何使其在更改表视图时仅执行一次吗?
代码:
[tableView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];
8月21日编辑:
伙计们,非常感谢你们!代码位于 cellforrowatindexpath 中。我将它移到了更改桌面视图的函数内部,它的工作方式就像一个魅力:D
This functions perfectly, but I want to make it an once-function, not fixed-function. When I change tableview with other data, the data displays at the index from previous tableview. So my solution to this is implementing the code below. When I implement this, it works, but when I scroll down, it scrolls up all the time, so it is virtually impossible to scroll down further. Any idea how to make it performs only once when I change tableview?
The code:
[tableView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];
Edit 21 august:
Guys, thank you very much! The code was in cellforrowatindexpath. I moved it to inside the function which changes tableview and it works like a charm :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用新数据重新加载表视图并将代码放入其中,则可以重写 reloadData 方法。在你的表视图控制器中类似这样的东西应该足够了:
如果每次向下滚动时它都向上滚动,我假设你将代码放在 cellForRowAtIndexPath 方法中,每次你想要显示单元格时都会调用该方法。这不是放置该代码的正确位置。
You could override the reloadData method if that is how you are reloading the Table View with new data and put the code in there. Something like this in your table view controller should suffice:
If it's scrolling up every time you scroll down, I assume you put the code in the cellForRowAtIndexPath method which will get called every time you want to present the cell. This is not the correct place to put that code.
它是一个一次性函数。最有可能的是,您的这段代码正在再次执行&再次。如果您将其保留在诸如
cellForRowAtIndexPath:
之类的频繁调用的函数中,则可能是导致此问题的原因。你把它放在哪里了?HTH,
阿克谢
It IS a once-function. Most probably, this code of yours is executing again & again. If you have kept this in a function such as
cellForRowAtIndexPath:
, which is called frequently, that may be the cause of this problem. Where have you put it?HTH,
Akshay