I'm programmatically creating a UIButton for my app. The few examples I've found online seem straightforward. Following the examples, I can create a button fine but it fails to do the action for TouchDown event I have wired for it. Here is the code for the button inside the ViewDidLoad of the parent view:
_searchButton = UIButton.FromType(UIButtonType.RoundedRect);
_searchButton.Frame = new RectangleF(swidth / 2 - 50f, 140f, 100f, 40f);
//_searchButton.BackgroundColor = UIColor.Clear;
_searchButton.SetTitle("Search", UIControlState.Normal);
_searchButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
_searchButton.UserInteractionEnabled = true;
_searchButton.TouchDown += delegate
{
Console.WriteLine("wicked");
};
this.View.AddSubview(_searchButton);
The only thing I can think of possibly the setting of UserInteractionEnabled. But they seem to be set to true by default. (Explicitly setting it true for the button doesn't help.)
What could I be doing wrong here?
I should add that the button should turn blue when I click on it, even if nothing is wired for TouchDown? That doesn't happen either.