ios - 如何向 UIButton 添加观察者?

标签 ios objective-c uibutton observer-pattern uicontrolevents

当用户触摸按钮(UIControlEventTouchUpInside)时,我希望收到信号。如何向 UIButton 添加观察者?

最佳答案

查看 UIControl 的文档.

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

此方法适用于从 UIControl 继承的任何内容(包括但不限于 UIButtons :)

关于ios - 如何向 UIButton 添加观察者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8520515/

相关文章:

iphone - 如何在 iOS 中从地址簿中获取电子邮件联系人?

iphone - 应用启动时检查耳机是否插入

ios - UIButton - alloc initWithFrame : vs. buttonWithType:

iphone - NSUserDefaults + NSMutableArray -> 存储2个数组并显示在tableview中

ios - 如何从 Swift 3 中的数据中提取 Int16

ios - 如何在 IOS 中以编程方式使 TTTAttributedLabel 居中对齐

ios - UIButton 突出显示的背景图像未显示

objective-c - 在 Objective C 方法中创建 UIButton

objective-c - 使用自定义表格 View 单元格中的按钮

ios - 使用临时存储打开文件