gpt4 book ai didi

iOS 自定义 View (.XIB) 按钮绑定(bind)不起作用

转载 作者:行者123 更新时间:2023-11-30 11:02:06 24 4
gpt4 key购买 nike

 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
}
}

There is custom view. Custom action button interface implemented in the Main controller. This code not working ... Why?

最佳答案

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

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 或 Storyboard 中的链接按钮操作。
  2. 检查生命周期“let mainFooter”。也许对象已经死了

关于iOS 自定义 View (.XIB) 按钮绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53222420/

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