未为 UIBarButtonItem 中的 UIButton 执行单击处理程序 [英] Clicked handler not executed for UIButton in UIBarButtonItem

查看:26
本文介绍了未为 UIBarButtonItem 中的 UIButton 执行单击处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的工具栏中有一个自定义按钮标题.这是我以前用过的.

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;

Clicked 事件永远不会被抛出,所以我的事件处理程序没有被调用.我希望能够随时添加 (+=) 和删除 (-=) 事件处理程序.

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.

推荐答案

尝试将您的事件添加到 someBarButtonItem 而不是按钮上,也许 UIBarButtonItem 没有将触摸正确转发到子视图?

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

这篇关于未为 UIBarButtonItem 中的 UIButton 执行单击处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆