I have two UITableViews. They contain basically the same rows, but each one has different information. I detect left and right swipes and then animate the views so that one appears to "slide off" the screen while the other "slides on". They can go in either direction.
There could be up to 20 rows in them. If they scroll in one, I'd like the other one to scroll with it so that when they swipe left or right, they stay aligned. Hopefully that makes sense.
Is there an event that will detect when the UITableView has been scrolled so that I could then "force" the other UITableView to scroll to the same exact spot?
Posts
@JeffRush UITableView does have a "Scrolled" event handler and then you can use the "ScrollToRow" method to force your second UITableView to scroll to the same row. Hope this helps.
Thanks Danny. I actually tried that before my post and it worked as long as the user had scrolled exactly so that the top of a row aligned with the top of the table. In other words, if at the top of the first UITableView you could only see half of the top row, the second UITableView would not quite be exactly aligned.
Have you tried to synchronize on the
ContentOffset
property?UITableView
is a subclass ofUIScrollView
, so if the tables have the same dimensions, my hunch is that would be worth exploring.I ended up using ScrollToRow on the first table as suggested so that it will always show the entire top row before I keep the other table in sync.
using Foundation;
using System;
using UIKit;
using CoreGraphics;
using System.Collections.Generic;
namespace ScrollTesting
{
public partial class ViewController : UIViewController,IUITableViewDelegate, IUITableViewDataSource
{
}
This works perfect!! Enjoy!!
//ContentSize = new CGSize(View.Bounds.Width, View.Bounds.Height+h),
Don't forget to uncomment this line.