gpt4 book ai didi

objective-c - 如何以编程方式连接 UIButton 和方法?

转载 作者:太空狗 更新时间:2023-10-30 03:59:03 24 4
gpt4 key购买 nike

在我的 UIView 中,我显示了一个 UIButton

在同一个 UIView 类中,我有一个方法我想在按下按钮时执行。

一切都以编程方式完成,而不使用 Interface Builder 时,如何将两者联系在一起?

最佳答案

使用 UIButton addTarget:action:forControlEvents: 消息为 UIControlEventTouchUpInside 事件指定一个选择器。

[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

关于objective-c - 如何以编程方式连接 UIButton 和方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8246817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com