iOS,监听tableVIew的偏移量

1. 添加监听

  [self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];

2.监听的处理

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

{

    if ([keyPath isEqualToString:@"contentOffset"])

    {

        CGPoint offset = [change[NSKeyValueChangeNewKey] CGPointValue];

    }

}

3.移除监听

[self.tableView removeObserver:self forKeyPath:@"contentOffset" context:nil];

posted @ 2016-08-12 14:04  阳光普照大地  阅读(7176)  评论(0编辑  收藏  举报