I have a MonoTouch iPhone app which has a UITableViewController
as it's main view controller.
I am trying to detect when the tableview is being scrolled with the code:
this.TableView.Scrolled += TableViewScrolled;
where TableViewScrolled(object sender, EventArgs e) { }
is my method being called.
But it fails to call the TableViewScrolled()
for some reason.
Does anyone have any experience with this?
My answer is not actually only about the scrolling, but because of the fact that I've spent quite an hour fighting with a problem caused by the scrolling event, I've decided to write answer here.
So, the problem for me was that after subscribing to:
this.myTableView.Scrolled += (sender, args) =>
{
...
};
my overriden methods of inherited from UITableViewDataSource class:
public override UIView GetViewForHeader(UITableView tableView, int section)
public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
stopped working (became not called). Which was... obviously, pretty unexpected!
So, I just had to override
public override void Scrolled(UIScrollView scrollView)
in the same datasource delegate instead of subscribing to existent event on table view.
I hope, someone won't get into such trouble!
@Krumelur's comment on the previous answer makes a very good point and IMO should have been an answer (not a comment).
The point is that if your set a Delegate
(or WeakDelegate
) to your UITableView
then it's events won't work anymore.
Why ? because to implement those events MonoTouch creates it's own internal delegate type for UIScrollView
(the parent of UITableView
) where it overrides the methods (of the delegate) and expose them as, more natural (in .NET), events inside the type.
This effectively means that you cannot mix those UITableView
events with your own delegate UITableViewDelegate
type (since the later will override the former).
Read this documentation: UIScrollViewDelegate
You can use:
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
}
or
- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView {
}
Good luck, Nathan
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With