gpt4 book ai didi

ios - IB 渲染 Storyboard时的可设计错误

转载 作者:可可西里 更新时间:2023-11-01 01:59:01 27 4
gpt4 key购买 nike

我尝试按照以下指南进行操作 12 ,但是当我尝试在 Storyboard 中呈现自定义 View 时出现错误。

Failed to render and update auto layout status for View Controller. The agent threw an exception.

这是我目前尝试过的:

@IBDesignable final class CustomView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}

private func setup() {
let customViewNib = loadFromNib()
customViewNib.frame = bounds
customViewNib.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
addSubview(customViewNib)
}

func loadFromNib() -> UIView {
let nib = UINib(nibName: "CustomView", bundle: Bundle.main)
let view = nib.instantiate(withOwner: self, options: nil).first as! UIView
return view
}
}

我已经设置了自定义 View 的文件所有者。

我创建了一个新的空项目来解决这个问题:

https://github.com/ivangodfather/CustomView

https://ufile.io/imr9p

enter image description here

最佳答案

问题似乎出在 bundle 中。

let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)

有关获取错误日志的更多信息,您可以查看此答案:https://stackoverflow.com/a/42678873/2000162

关于ios - IB 渲染 Storyboard时的可设计错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48093466/

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