【问题标题】:"Also create xib file" button disabled“同时创建 xib 文件”按钮已禁用
【发布时间】:2016-12-30 13:03:24
【问题描述】:

我在创建UIView's 子类时遇到了这个问题。例如,创建UIViewControllersUITableViewCells 是可以的。

为什么会这样?

我使用 cmd+N 和 Xcode 版本 7.3.1: 创建视图

【问题讨论】:

  • 我看到了解决方案,但实际上没有人回答这个问题:为什么?

标签: ios xcode uiview xib


【解决方案1】:

分别创建View和Cocoa Touch Class,但名称相同,然后将xib的Class设置为文件名。

【讨论】:

    【解决方案2】:

    您可以添加将解决此问题的自定义 Xcode 模板或添加现有模板。阅读更多如何创建并将其添加到 Xcode here

    模板可以在here找到。

    【讨论】:

      【解决方案3】:

      是的,根据@PRECover,xib 复选标记按钮始终被禁用 为了帮助您更多,我正在描述使您轻松的步骤

      步骤 - 1:创建没有 xib 的 UIView 类。 Step - 2 : 去创建一个新文件,这次选择资源模板

      第 4 步 - 现在转到视图类并编写“getView”函数

      class SampleView: UIView {
      
      /*
      // Only override drawRect: if you perform custom drawing.
      // An empty implementation adversely affects performance during animation.
      override func drawRect(rect: CGRect) {
          // Drawing code
      }
      */
      
      func getView() -> UIView {
          return NSBundle.mainBundle().loadNibNamed("SampleView", owner: nil, options: nil)[0] as! UIView
      }
      }
      

      第 5 步 - 编写下面的方法并调用它以将视图添加到主视图中(您想要的任何位置)

          func designSampleView()
      {
          let sview = (SampleView()).getView();
          NSLog("Test ", "");
          self.view.addSubview(sview);
      }
      

      【讨论】:

        猜你喜欢
        • 2022-01-22
        • 1970-01-01
        • 2020-12-12
        • 1970-01-01
        • 1970-01-01
        • 2015-06-25
        • 1970-01-01
        • 1970-01-01
        • 2017-07-24
        相关资源
        最近更新 更多