Is it possible to add observer to tableView.contentOffset?
Swift 5
tableContentObserver = table.observe(\UITableView.contentOffset, options: .new) { [weak self] table, change in
self?.navigationItem.rightBarButtonItem?.title = "\(change.newValue)"
}
UITableView
is a UIScrollView
subclass so you can use the UIScrollViewDelegate
method scrollViewDidScroll:
to be notified when the view scrolled. Check the contentOffset
of the scrollView
in that method
contentOffset
is a key path, so you can also observe its changes using KVO
[self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];