Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
618 views
in Technique[技术] by (71.8m points)

ios - This class is not key value coding-compliant (with storyboard)

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.

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;
        }
    }
}

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 :

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...