gpt4 book ai didi

ios - 自定义 View 未初始化

转载 作者:行者123 更新时间:2023-11-30 11:40:08 25 4
gpt4 key购买 nike

我的项目中包含单选按钮的自定义 View 。我已经从 Storyboard中的 View 到 View Controller 中的导出建立了连接。

当我尝试访问该 socket 以设置 View 中的委托(delegate)时,应用程序崩溃了(在控制台上不显示任何错误)。我尝试设置该对象的委托(delegate)进行测试,因为在尝试设置其属性之一时出现 EXC_BAD_ACCESS(代码=2,地址=0x000..)错误。当我尝试打印对象的描述时,它不会将其识别为我将其设置为的自定义类的对象,而只是一个 UIView。我没有访问 View Controller 或任何其他 View Controller 中的 socket 的代码。

我尝试重新连接 socket ,但这不是问题,因为它在应用程序的测试方案上运行良好。应用程序在应用程序的App Store方案上崩溃。

注意: -

  1. 由于我不太熟悉该计划的所有细节可能会带来这种意外行为(如果有的话),以及如何分享此类行为的细节,请让我知道额外的信息评论中可能与调试此问题相关的详细信息,我将用详细信息更新问题。

  2. 另请注意,我已将自定义 View 类包含到应用商店目标中(因此这不是问题)。

感谢任何帮助。谢谢

更新

  1. 分配委托(delegate)的代码是viewDidLoad()

    customView.delegate = self

  2. 自定义类有两个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)
    }

另请注意,我有一个非常相似的自定义 View ,其代码几乎相同,但 UI 不同,并且该 View 工作时没有任何问题。

更新:添加设备崩溃日志的图像。 1 , 2 , 3

最佳答案

抱歉,我在得到答案后忘记更新这个问题的答案。

所以我解决了这个问题。这似乎是一个与目标相关的问题。 Storyboard中 socket 的 View 属于不同的模块。

enter image description here

在身份检查器中,该模块被选为企业模块。所以它没有被包含在应用商店构建中。当我将模块设置为空时,该应用程序对于这两种方案都运行良好。

我不知道如何更好地解释它。如果有人可以通过更多解释来阐明这一点,我们将不胜感激。

无论如何,这就是最终的效果。

关于ios - 自定义 View 未初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49356351/

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