Clicked handler not executed for UIButton in UIBar

2019-08-14 16:03发布

问题:

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.

回答1:

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