简体   繁体   中英

UITableViewController contentOffset returns nil

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:(UIScrollView *)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有一个rectForRowAtIndexPath方法,您可能对此感兴趣。

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]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM