【问题标题】:This class is not key value coding-compliant (with storyboard)此类不符合键值编码(带有情节提要)
【发布时间】:2020-08-10 14:35:23
【问题描述】:

我刚刚开始使用 Xamarin 进行 iOS 开发,似乎遇到了障碍。我正在尝试创建一个自定义表格单元格来显示一些数据。因此,从各种在线资源中获取提示(例如,请参阅 here),我创建了一个 .xib 文件,删除了 Xamarin 自动创建的视图并将其替换为 UITableViewCell。我在我的单元格中添加了一些标签,我用RegisterNibForCellReuse 注册了我的单元格,并设置了从UITableViewSource 继承的类,以便在适当的时候返回我的自定义单元格。到目前为止一切顺利。

当我使用自定义单元格中的任何控件并尝试创建插座时,问题就开始了。在 XCode 中创建插座,一切看起来都很好。回到 Xamarin,我可以看到它自动为它创建了一个属性。

[Register ("MyCustomCell")]
partial class MyCustomCell
{
    [Outlet]
    MonoTouch.UIKit.UILabel MyLabel { get; set; }



    void ReleaseDesignerOutlets ()
    {
        if (MyLabel != null) {
            MyLabel.Dispose ();
            MyLabel = null;
        }
    }
}

但是当我尝试运行代码时,我得到一个运行时错误,提示 This class in not key value coding-compliant for key the key MyOutlet

知道会发生什么吗? Xamarin 文档提出了一个可能的原因here,但我不确定它是否相关。我在 Xamarin 创建的 任何 设计器文件中没有看到类似的东西,它们都很好。我尝试将上面的属性定义替换为使用Connect 属性而不是Outlet 并使用GetNativeFieldSetNativeField 的属性定义,但我看到了相同的结果。

【问题讨论】:

    标签: ios xamarin


    【解决方案1】:

    在我的情况下,我遇到这个问题有一段时间了,结果证明是与构建过程有关的问题。以下为我修复了它:

    右键单击您的项目,选择“选项”,然后在“构建”子标题下选择“iOS 构建”,将 -f 添加到“附加 mtouch 参数”并重新构建。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,最后我在 XCode 中执行了 Product->Clean,它解决了我的问题。

      【讨论】:

        【解决方案3】:

        右键单击您的项目,选择“选项”,然后在“构建”子标题下选择“iOS 构建”,将 -f 添加到“附加 mtouch 参数”并重新构建。

        【讨论】:

          【解决方案4】:

          在我的例子中,我正在为几个按钮创建动作,但我不小心创建了一个插座,而不是一个动作。我刚刚删除了@IBOutlet 行。

          我的错误是:

           this class is not key value coding-compliant for the key Button_Twitter_Clicked.'
          

          再次,就我而言,我从以下位置找到了解决方案:

          http://www.tech-recipes.com/rx/52021/how-do-i-fix-the-issue-this-class-is-not-key-value-coding-compliant-for-the-key-in-xcode-6/

           - Click the "Show Find Navigator" on the left hand side
           - Search for the key above that gave the error, in my case it was the "Button_Twitter_Clicked" key.
           - Double click on the result (my case, I clicked on the View Controller:Outlet
           - On the right hand side, find the Key that was in the exception thrown during runtime (Has exclamation mark)
             (States that the view controller does not have an outlet named [outletname]
           - Click the X button
           - Recompile :)
          

          希望这会有所帮助!

          【讨论】:

            【解决方案5】:

            我同意理查德的回答。

            您可以做的另一件事是重建项目。是 -f 参数的作用。

            【讨论】:

              【解决方案6】:

              我遇到了同样的问题,“清洁”解决方案对我不起作用。我的解决方案是:

              1. 右键单击您的项目,选择“选项”

              2. 在 Build 部分下选择 iOS Build

              3. 并在链接器选项中选择“链接所有程序集”链接器行为。

              【讨论】:

              • 这不是解决方案。这没有任何意义。
              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2017-10-15
              • 1970-01-01
              • 2013-12-03
              • 2019-10-16
              • 1970-01-01
              相关资源
              最近更新 更多