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

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

问题描述

我刚开始使用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 替换上面的属性定义,并使用 GetNativeField SetNativeField ,但我看到相同的结果。

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天全站免登陆