我想在用戶觸摸按鈕(UIControlEventTouchUpInside)時發出信號。如何將觀察者添加到UIButton?如何將觀察者添加到UIButton?
2
A
回答
4
看看UIControl的文檔。
[myButton addTarget:self
action:@selector(touch:)
forControlEvents:UIControlEventTouchUpInside];
此方法適用於任何從UIControl
(包括繼承,但其中目標是在UIButton的加入或實現的類不限於UIButtons
:)
2
// add target and action
[myButton addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
。如果您將addTarget設置爲零,則操作將通過響應者鏈直到找到響應buttonClicked:選擇器的響應者。 buttonClicked:選擇器實現如下:
-(void)buttonClicked:(id)sender
{
// do stuff here
}
相關問題
- 1. 如何將觀察者添加到NSManagedObject?
- 2. 將觀察者添加到BOOL變量
- 3. 將觀察者添加到NSString中
- 4. 如何在UISlider上添加觀察者
- 5. 如何將基於時間的觀察者添加到Scala Future?
- 6. 將通知觀察者添加到自定義類
- 7. C#通過JSON和REST API將觀察者添加到Jira isse
- 8. 觀察者模式 - 觀察者創建
- 9. 如何在觀察者
- 10. 當觀察者的觀察者的壽命長於可觀察到的
- 11. 觀察者模式 - 將信息傳遞給觀察者
- 12. 如何避免添加多個NSNotification觀察者?
- 13. 如何在UIView中爲subviews.count添加觀察者?
- 14. Android「觀察者」
- 15. NSNotificationCenter將所有實例添加爲觀察者
- 16. Java觀察者和可觀察的
- 17. 如何將3Dtouchforce添加到UIButton?
- 18. 如何將陰影添加到UIButton?
- 19. 如何將屬性添加到UIButton?
- 20. 初學者JavaFX觀察者
- 21. NSNotificationCenter:添加觀察者,但只有未註冊才能觀察?可以查詢對象的觀察狀態?
- 22. 觀察者模式
- 23. NSInternalInconsistencyException觀察者contentSize
- 24. RxJava 2.0 - 如何將觀察者轉換爲發佈者
- 25. 將觀察者添加到UITableViewController中的通知中心的位置
- 26. 將通知中心觀察者添加到特定的NSTextField中 - MacOS
- 27. 添加而當觀察到從knockout.mapping
- 28. 誰是觀察者,誰是可觀察者?
- 29. 觀察者模式Java - 使用線程的多個觀察者
- 30. 如何從觀察者內部返回?