让 UIButton showDetails 接受参数

发布于 2024-11-18 10:41:09 字数 194 浏览 3 评论 0原文

我的 MKMapView 上有许多 UIButton 元素。当用户单击按钮时,我会收到 showDetails 通知。但是我如何知道用户点击了哪个按钮呢?我所知道的唯一技巧是传入整数标签值。当然必须有一种更优雅的方式。我尝试对 UIButton 进行子类化,但由于它是一个集群,因此我无法对它进行子类化并使用 UIButton 的所有现有功能。

谢谢 德肖恩

I have many UIButton elements on my MKMapView. When the user clicks on a button I get a showDetails notification. But how do I tell which button the user clicked on? The only hack I know of is to pass in the tag value which is an integer. Surely there must be a more elegant way. I tried subclassing UIButton but since it is a cluster, I cannot subclass it and use all of theUIButtons existing functionality.

Thanks
Deshawn

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北陌 2024-11-25 10:41:09

标签是识别的好方法,您还可以使用当前标题来区分所有按钮是否具有不同的标题。这是一个代码片段

[[button currentTitle] isEqualToString:@"your desired string"]; 

,但我更喜欢使用标签。

tag is a good way to identify you can also use current title to differentiate if all buttons have different titles. here is a code snippet

[[button currentTitle] isEqualToString:@"your desired string"]; 

But I prefer use tags.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文