此类不符合键值编码(带故事板) [英] This class is not key value coding-compliant (with storyboard)

查看:36
本文介绍了此类不符合键值编码(带故事板)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm just getting started in iOS development with Xamarin and seem to have hit a road block. I'm trying to create a custom table cell to display some data. So taking prompts from various online sources (see here for example), I created a .xib file deleted the view that Xamarin automatically created and replaced it with a UITableViewCell. I added a few labels to my cell, I registered my cell with RegisterNibForCellReuse and set up my class that inherits from UITableViewSource to return my custom cell when appropriate. So far so good.

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

The problem starts when I take any of the controls in my custom cell and try to create an outlet. In XCode create the outlet and everything looks okay. Back in Xamarin I can see it's automagically created a property for it.

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



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

但是当我尝试运行代码时,我收到一个运行时错误说这个类不符合键值编码,用于键 MyOutlet

But when I try and run the code I get a runtime error saying This class in not key value coding-compliant for key the key MyOutlet

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

Any idea what might be happening? The Xamarin docs suggests a possible cause here, but I'm not sure it's relevant. I don't see anything like that in any of the designer files Xamarin has created and they've all been fine. I tried replacing the property definition above with one that uses the Connect attribute instead of Outlet and uses GetNativeField and SetNativeField, but I see the same result.

推荐答案

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

I was having this problem for a while in my case it turned out to be a problem relating to the build process. The following fixed it for me :

右键单击您的项目,选择选项",然后选择构建"子标题下的iOS 构建",将 -f 添加到其他 mtouch 参数"并重建.

Right-click your project, select 'Options' then 'iOS Build' under the 'Build' sub-heading, add -f to 'Additional mtouch arguments' and rebuild.

这篇关于此类不符合键值编码(带故事板)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆