Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios EXC\u错误\u访问内核\u无效\u地址_Ios_Swift_Memory_Memory Leaks_Uibutton - Fatal编程技术网

Ios EXC\u错误\u访问内核\u无效\u地址

Ios EXC\u错误\u访问内核\u无效\u地址,ios,swift,memory,memory-leaks,uibutton,Ios,Swift,Memory,Memory Leaks,Uibutton,在上两个版本中,我们收到了太多与CFNetwork和EXC_BAD_ACCESS KERN_INVALID_ADDRESS相关的崩溃。因此,我们试图找出问题所在,并启用了NSZombie,并通过调试内存图进行验证。我们在下面的图片上得到了一个紫色的警告 在以编程方式创建一个按钮(如下图所示)时是否存在任何问题,并为另一个图像问题提供一些指针 class CustomButton{ var didTab: (() -> Void)? private let butt

在上两个版本中,我们收到了太多与CFNetwork和EXC_BAD_ACCESS KERN_INVALID_ADDRESS相关的崩溃。因此,我们试图找出问题所在,并启用了NSZombie,并通过调试内存图进行验证。我们在下面的图片上得到了一个紫色的警告

在以编程方式创建一个按钮(如下图所示)时是否存在任何问题,并为另一个图像问题提供一些指针

class CustomButton{

    var didTab: (() -> Void)?


    private let button  :UIButton
    init(text: String,fontSize: CGFloat) {
        button = UIButton()
        button.setTitle(text, for: .normal)
        button.titleLabel?.font = UIFont (name: "MuseoSans-500", size: fontSize)
        button.translatesAutoresizingMaskIntoConstraints = false
        button.addTarget(self, action: #selector(_didTabButton), for: .touchUpInside)
    }

    func setImage(_ image: UIImage?) -> Self{
        button.setImage(image, for: .normal)
        return self
    }

    func setTitleColor(_ color:UIColor, _ state: UIControl.State)-> Self{
        button.setTitleColor(color, for: state)
        return self
    }
    func addTarget(target: Any?, action: Selector, fors:  UIControl.Event) -> Self{
        button.addTarget(target, action: action, for: fors)
        return self
    }

    func isHidden(bool: Bool)-> Self{
        button.isHidden = bool
        return self
    }

    func changeColor(color:UIColor) -> Self{
        button.backgroundColor = color
        return self
    }

    func buildUI() -> UIButton{
        return button
    }

    @objc
    private func _didTabButton() {
        didTab?()
    }
}
控制器:

let notificationButton = CustomButton(text: "", fontSize: 20)
    .setImage(UIImage(named:"notification"))
    .addTarget(target: self, action: #selector(notificationList), fors: .touchUpInside)
    .buildUI()


func setUpView(){
    view.addSubview(notificationButton)
}
func setUpConstrainsts(){
    //notificationButton
    notificationButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 10).isActive = true
    notificationButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 5).isActive = true
    notificationButton.widthAnchor.constraint(equalToConstant: 40).isActive = true
    notificationButton.heightAnchor.constraint(equalToConstant: 40).isActive = true

}

您没有为您的按钮提供任何框架。我们已通过编程方式添加了约束,并且按钮按预期工作。