开发者

How to handle no animation with UITableView selectRowAtIndexPath:animated:YES?

I'm using UITableView's selectRowAtIndexPath:animated:scrollPosition to slide some of my UITableViewCells into place when a user 开发者_JS百科selects them. When the animation completes, I want to display some additional metadata over the cell. The problem I'm having is that I can't seem to figure out a way to determine whether or not the UITableView will actually scroll, so that my metadata drawing routine can be called (in scrollViewDidEndScrollingAnimation). If the position of the cell is exactly where it should be when a user selects one, then no animation is needed, and scrollViewDidEndScrollingAnimation never gets called. Is there an easy way to determine if the UITableView doesn't need to scroll, or do I need to do all of these calculations manually at the time when I call selectRowAtIndexPath? I can't help but think that I'm missing some easy way to make this determination.

(Note: One reason I'd prefer not to do the calculations myself is that my rows are of different sizes, and determining if the scroll offset is positioned where it should be is a bit of a hassle)


One way is to use delayed performance. Store the current contentOffset. Do the selection with selectRowAtIndexPath:animated:scrollPosition: and then immediately call performSelector:withObject:afterDelay: with a very small delay (0.1, say). In the method you call with performSelector:..., ask for the current contentOffset again. If it hasn't changed, I think you may assume it isn't going to - we are not going to scroll! So you may proceed with your metadata display now. If it has changed, then do nothing and let your scrollViewDidEndScrollingAnimation take care of it.

I know this seems sort of skanky, but I find myself using delayed performance a lot to work around automatic animations of this sort.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜