开发者

UITableViewController contentOffset returns nil

开发者 https://www.devze.com 2023-01-05 19:18 出处:网络
I am trying to get the scroll position of my UITableView, however when I implement any of the UIScrollViewDelegate methods, contentOffset always returns nil for me.

I am trying to get the scroll position of my UITableView, however when I implement any of the UIScrollViewDelegate methods, contentOffset always returns nil for me.

For example:

- (void)scrollViewDidEndDecelerating:(UIScr开发者_如何学CollView *)scrollView {
    NSLog(@"offset: %@", [scrollView contentOffset]);
}

The log returns as offset: (null) when stopping a scroll motion in the simulator.

I can recreate this with the first example - SimpleTableView - in Apple's TableViewSuite. The RootViewController is a UITableViewController, and if I place the above method in the implementation file this is what happens. What am I missing here?


UITableView has a method rectForRowAtIndexPath which may be of interest to you.


Well, obviously I am new to this. It turns out the logger has no idea how to output a CGPoint, which is frustrating since it acts like it doesn't work by outputting null. In order to see the value in the log I had to do this:

NSLog(@"offset y %@", [[NSNumber numberWithFloat:scrollView.contentOffset.y] stringValue]);
0

精彩评论

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