iOS自定义视图(.XIB)按钮绑定不起作用

时间:2018-11-09 08:48:03

标签: ios swift xib

 protocol CustomViewAction: class {
  func customActionButton(_ sender: UIButton)
 }

 class MainFooter: UIView { 
   weak var delegate: CustomViewAction?

   @IBAction func languageButton(_ sender: UIButton) {
     self.delegate?.customActionButton(sender)
   } 
   private func loadNib() {...}
 }


class MainCont: CustomViewAction {
 ...
 let mainFooter = MainFooter()
 mainFooter.frame = view.frame
 mainFooter.delegate = self

 func customActionButton(_ sender: UIButton) {
  ... not working
 }
}
  

有自定义视图。在主控制器中实现的自定义操作按钮界面。   该代码不起作用...为什么?

1 个答案:

答案 0 :(得分:0)

这是非常糟糕的代码) 请修复

protocol CustomViewDelegate: class {
 func actionTouchCustomView(button:UIButton)
}


class MainFooterView: UIView { 
weak var delegate: CustomViewDelegate?

 //MARK: Handle Actions
@IBAction func handleTouchActionLanguageButton(_ sender: UIButton) {
 self.delegate?.actionTouchCustomView(sender)
} 

 //MARK: Life cycle
private func loadNib() {...}
}

class MainCont: CustomViewDelegate {
...
let mainFooter = MainFooter()
mainFooter.frame = view.frame
mainFooter.delegate = self

//MARK -  CustomViewDelegate
func actionTouchCustomView(button:UIButton) {
... not working
}
}
  1. 在XIB或情节提要中检查链接按钮的操作。
  2. 检查生命周期“让mainFooter”。也许物体已经死了