gpt4 book ai didi

ios - IB Designables : Failed to render and update auto layout status

转载 作者:IT王子 更新时间:2023-10-29 05:07:44 27 4
gpt4 key购买 nike

我有一个自定义 View (xib),其中有一个 UIButton,我使 id IBDesignable 执行以下操作:

UserView.swift

import UIKit

@IBDesignable
class UserView: UIView {

@IBOutlet var view: UIView!
@IBOutlet weak var userButton: UIButton!

override init(frame: CGRect) {
super.init(frame: frame)
load()

}

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

fileprivate func load() {
Bundle.main.loadNibNamed("UserView", owner: self, options: nil)
addSubview(view)
self.frame = bounds
}

}

UserView.xib

  • 添加了 UIButton 并设置了约束
  • 设置文件的所有者:UserView

Storyboard

我将 UIView 添加到 Bar Button Item 并分配了 UserView 类,但没有呈现任何内容,并且出现以下构建错误:

error: IB Designables: Failed to render and update auto layout status for FoodViewController (bR3-Kz-wX7): The agent threw an exception.

我目前的环境:Xcode 9, Swift 4

最佳答案

我只是遇到了完全相同的问题,唯一对我有用的是我必须为我想要的 Nib 获取 Bundle,而不是使用主 Bundle。本质上改变:

Bundle.main.loadNibNamed("UserView", owner: self, options: nil)

收件人:

let bundle = Bundle(for: UserView.self)
bundle.loadNibNamed("UserView", owner: self, options: nil)

这很奇怪,就我而言,在运行时比较 LLDB 中的两个 Bundle 时,它​​们是相同的(类名不同,但我的其余设置与 OP 相同)

lldb screenshot已更新

为什么从主包加载 NIB 不起作用?

因为当 InterfaceBuilder 渲染时它并没有运行应用程序。没有“主应用程序包”。

关于ios - IB Designables : Failed to render and update auto layout status,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46723683/

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