开发者

iPhone - How may I know if scrollToRowAtIndexPath will scroll something

I have some things to do at scrollViewDidEndScrollingAnimation time with a DoThis function. But sometimes, scrollToRowAtIndexPath with animate=YES does not scroll anything.

So how can I know if the scrolling will be done to be able to f开发者_运维技巧orce an alternative function DoThisWithNoScrollOccured call after the scrollToRowAtIndexPath call ?


Joshua's answer is pretty close, but I've run into situations in which scrolling will occur, even if the indexPath you wish to scroll to is listed in indexPathsForVisibleRows.

For example, if you are scrolling to an indexPath using the scroll position UITableViewScrollPositionTop, scrolling will still occur when the indexPath is listed in indexPathsForVisibleRows - if your indexPath is not the first visible indexPath and there are more displayable rows after those listed in indexPathsForVisibleRows.

In this scenario, the UITableView attempts to scroll the indexPath as close as possible to the topmost display position.

I haven't tried it, but I would expect UITableViewScrollPositionBottom to have a similar effect if there are displayable rows above the indexPath you'll be scrolling to, and the indexPath you're scrolling to is not the last visible indexPath in indexPathsForVisibleRows.


With iOS7, neither of these approaches worked for me, probably because of the content inset of my UITableView. indexPathsForVisibleRows returned index paths for rows that could not be interacted with because they were behind the UINavigationBar. Instead, I did the following:

CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
if (rect.origin.y != self.tableView.contentOffset.y + self.tableView.contentInset.top) {
   // scrollToRowAtIndexPath will animate and callback scrollViewDidEndScrollingAnimation
} else {
   // scrollToRowAtIndexPath will have no effect
}             


You can check the indexPathsForVisibleRows and see if the RowAtIndexPath you are trying to scroll to is already visible. If it is already visible, there will be no scrolling.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜