Clicked handler not executed for UIButton in UIBarButtonItem

本小妞迷上赌 提交于 2019-12-13 02:00:30

问题


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?



来源:https://stackoverflow.com/questions/32198601/clicked-handler-not-executed-for-uibutton-in-uibarbuttonitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!