我的项目中包含单选按钮的自定义视图。我已经从故事板中的视图连接到视图控制器中的插座。
当我尝试访问该出口以在视图中设置委托时加载,应用程序崩溃(在控制台上不显示任何错误)。我试图设置该对象的委托进行测试,因为我在尝试设置其中一个属性时收到了EXC_BAD_ACCESS(code = 2,address = 0x000 ..)错误。当我尝试打印对象的描述时,它不会将其识别为我设置的自定义类的对象,而只是一个UIView。我没有访问视图控制器或任何其他视图控制器中的插座的代码。
我已经尝试重新连接插座,但这不是问题,因为它在应用程序的测试方案上正常工作。该应用程序在应用程序的App Store方案中崩溃。
注意: -
由于我不熟悉该计划的所有细节可能带来的这种意外行为(如果有的话),以及如何分享这些行为的细节,请让我知道额外的可能与评论中调试此问题有关的详细信息,我将更新详细信息。
另请注意,我已将自定义视图类包含在应用商店目标中(因此不是问题)。
感谢任何帮助。感谢
更新
代码分配委托已完成viewDidLoad()
customView.delegate = self
自定义类有两个init(我没有写它,所以不知道为什么)
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initializeSubviews()
}
override init(frame: CGRect) {
super.init(frame: frame)
initializeSubviews()
}
func initializeSubviews() {
let xibFileName = "xibName"
let view = NSBundle(forClass: self.dynamicType).loadNibNamed(xibFileName, owner: self, options: nil)![0] as! UIView
view.tag = 1111
self.addSubview(view)
view.frame = self.bounds
radio1Img.hidden = true
let radio1ImgTappedG: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(RadioButton2.radio1ImgTapped))
radio1Img.addGestureRecognizer(radio1ImgTappedG)
let radio1CaptionTappedG: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(RadioButton2.radio1CaptionTapped))
radio1Caption.addGestureRecognizer(radio1CaptionTappedG)
let radio2ImgTappedG: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(RadioButton2.radio2ImgTapped))
radio2Img.addGestureRecognizer(radio2ImgTappedG)
let radio2CaptionTappedG: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(RadioButton2.radio2CaptionTapped))
radio2Caption.addGestureRecognizer(radio2CaptionTappedG)
let radio3ImgTappedG: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(RadioButton2.radio3ImgTapped))
radio3Img.addGestureRecognizer(radio3ImgTappedG)
let radio3CaptionTappedG: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(RadioButton2.radio3CaptionTapped))
radio3Caption.addGestureRecognizer(radio3CaptionTappedG)
let radio4ImgTappedG: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(RadioButton2.radio4ImgTapped))
radio4Img.addGestureRecognizer(radio4ImgTappedG)
let radio4CaptionTappedG: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(RadioButton2.radio4CaptionTapped))
radio4Caption.addGestureRecognizer(radio4CaptionTappedG)
radio1Caption.hidden = true
radio1Caption.textColor = UIColor(netHex: 0x8C8C8C)
radio2Img.hidden = true
radio2Caption.hidden = true
radio2Caption.textColor = UIColor(netHex: 0x8C8C8C)
radio3Img.hidden = true
radio3Caption.hidden = true
radio3Caption.textColor = UIColor(netHex: 0x8C8C8C)
radio4Img.hidden = true
radio4Caption.hidden = true
radio4Caption.textColor = UIColor(netHex: 0x8C8C8C)
}
另请注意,我有一个非常相似的自定义视图,几乎相同的代码,但不同的UI,并且该视图没有任何问题。