我有一個自定義UIView子類有一些UIButtons追加。對於每個按鈕,都有一個在UIViewController上定義的目標操作,該操作包括自定義UIView。以編程方式創建自定義視圖與按鈕目標
不知何故TouchUpInside事件永遠不會被捕獲在自定義視圖內,包括ViewController。由於UIViews是UIResponderChain的一部分,我想知道爲什麼事件沒有被解僱?將目標行爲委託進行還是應該以另一種方式進行?
自定義UIView子類:CustomView
let button = UIButton(frame: CGRectMake(10.0, 10.0, 100.0, 100.0))
button.addTarget(self.delegate, action: "buttonTapped:", forControlEvents: .TouchUpInside)
的ViewController
// Include the custom view
let customView = CustomView()
customView.delegate = self
self.view.addSubview(customView)
...
func buttonTapped(sender: AnyObject!) {
// Doesn't get called
}