ios:在xib中加载自定义 View

标签 ios interface-builder

我在 xib 中设计了我的自定义 View 。我有 CustomView.h/m + CustomView.xib .在 xib 文件中,我将 View 类设置为 CustomView。

现在我想在其他 xib 中使用这个 View 。我创建了另一个 xib,添加了 View 并将其设置为 CustomView ,但它没有加载。

如何正确加载我的 CustomView?

最佳答案

简短的回答:是的。

You can use CustomView.h/m in as many .XIB files as you see fit, including .storyboard



问题在于如何加载第二个 View 。
    if let navigationController = self.navigationController {
        let sb = UIStoryboard(name: "Main", bundle: nil)
        if let vc = sb.instantiateViewControllerWithIdentifier("id") as? UIViewController {
            navigationController.pushViewController(vc, animated: true)
        }
    }

看:
  • Correct way to load a Nib for a UIView subclass
  • load view form StoryBoard that does not have a Segue .
  • 关于ios:在xib中加载自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31156046/

    相关文章:

    iphone - 如何在界面构建器中设置stretchableImageWithLeftCapWidth?

    ios - 为什么某些 unicode 字符在 Interface Builder 中不显示?

    ios - 如何将数字侧设置为名称电话垫键盘类型的默认值(键盘打开时)

    ios - 一元运算符 '~' 不能应用于类型 'MyType' 的操作数

    objective-c - 如何在 Storyboard中设置初始 ViewController 的委托(delegate)

    ios - 在 arm64 上将字符串转换为整数?

    ios - 在 Storyboard 中更改 iphone 4 和 iphone 5 之间的背景图像?

    ios - 蓝牙 HM-10 PIN 连接,身份验证/安全

    ios - MVVMCross + SQLCipher = 不可能?

    iOS - Interface Builder - 自动布局两个标签