1

I want to have a custom button title in my toolbar. This is what I've used before.

UIButton someButton = UIButton.FromType (UIButtonType.System);
someButton.SetTitle ("My custom button title", UIControlState.Normal);
someButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
someButton.SizeToFit ();
someBarButtonItem = new UIBarButtonItem (someButton);

someButton.Clicked += someEventHandler;

The Clicked event is never thrown and so my event handler is not called. I want to be able to add (+=) and remove (-=) the event handler at any time.

testing
  • 19,681
  • 50
  • 236
  • 417

1 Answers1

1

Try to add your event onto the someBarButtonItem instead of the button, maybe the UIBarButtonItem is not forwarding touches correctly down to subviews?

Michiluki
  • 505
  • 3
  • 17
  • You are right. I should add the event to `UIButton` and not to `UIBarButtonItem`. Now I use `someButton.TouchUpInside += someEventHandler;` and it seems to work. – testing Aug 25 '15 at 08:19