Detecting Scroll In A Nested UITableView

JSpringJSpring GBUniversity ✭✭

Hi,

This stems from http://forums.xamarin.com/discussion/comment/172504/#Comment_172504

I have a UITableView within a UIView, the tables source is set to a child class of UITableViewSource which seems to inherit from UIScrollViewDelegate. However overriding Scrolled and putting in a private func with an export for scrollViewDidScroll: still does not fire the event when the user scrolls the table view.

I was wondering if anyone else has come across this issue. My code for the scrollViews are as follows:

    #region Underlying Scroll View Related
    [Export("scrollViewDidScroll:")]
    private void ScrollViewDidScroll (UIScrollView scrollView)
    {
        var currentOffset = scrollView.ContentOffset.Y;
        var maxOffset = scrollView.ContentSize.Height - scrollView.Frame.Size.Height;

        float bottomPadding = 10.0f; // This should be equal to the cell height. Then can set to x amt of cells early
        if(maxOffset - currentOffset <= bottomPadding)
        {
            Console.WriteLine ("At Bottom Of The Scroll View / Table");
            if(tv != null)
                launchReload (tv, null);
        }
    }

    public override void Scrolled (UIScrollView scrollView)
    {
        ScrollViewDidScroll (scrollView);
    }
    #endregion

Posts

  • MarkSmith.8123MarkSmith.8123 USXamarin Team, University, XamUProfessors Xamurai

    Hi @JSpring --

    I'm not sure why Scrolled isn't working for you. I'm seeing it just fine -- here's a sample which outputs the current scrolled position into the debug console as you scroll the UITableView:

    https://dl.dropboxusercontent.com/u/2174873/Xamarin.Samples/TableViewScroll.zip

    Try running this, scroll the contents and watch the output window. I didn't do anything tricky -- just put a UITableView into the UI, set a UITableViewSource and overrode the methods. Is that what you are doing as well?

    Good luck!
    Mark Smith
    Xamarin University | Curriculum

  • JSpringJSpring GBUniversity ✭✭

    Got it working eventually by putting an Export in - will have a look into this further once we get the next release out and I can play around.

    Thanks,
    Jayden

Sign In or Register to comment.