Reputation: 2210
I have a list of buttons that show up in a UIView that's assigned to a UIScrollView. Before I add them to the UIView that eventually gets added to the UIScrollView, I assign a TouchUpInside event handler to each one.
The problem that I have is, when I scroll down in the list, all of the UIButtons below the viewable area don't fire the event handler.
I tried removing the event handlers and reassigning them on the Scroll event of the UIScrollView but still nothing. What am I missing?
Upvotes: 0
Views: 251
Reputation: 192
I have reproduced your case in this test controller. The UIButtons that fall under the view area successfully trigger the TouchUpInside event. Maybe you can compare with your own code and see the difference. (include statements has been left out)
public class ScrollController : UIViewController
{
UIScrollView scroll;
List<UIButton> buttons;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
scroll = new UIScrollView();
scroll.Frame = View.Bounds;
View.AddSubview(scroll);
scroll.ContentSize = new SizeF(0, 1000);
buttons = new List<UIButton>();
for(int i = 0; i < 10; i++)
{
var button = CreateButton(i * 75, i.ToString());
buttons.Add(button);
scroll.AddSubview(button);
}
}
UIButton CreateButton(float y, string title)
{
var button = UIButton.FromType(UIButtonType.RoundedRect);
button.SetTitle(title, UIControlState.Normal);
button.Frame = new System.Drawing.RectangleF(0, y, 200, 50);
button.TouchUpInside += HandleButtonTouchUpInside;
return button;
}
void HandleButtonTouchUpInside (object sender, EventArgs e)
{
var button = sender as UIButton;
Console.WriteLine("{0} touched", button.Title(UIControlState.Normal));
}
}
Upvotes: 1