Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

xamarin

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.

like image 920
Matt Burland Avatar asked Jun 05 '13 13:06

Matt Burland


4 Answers

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.

like image 112
Richard Adams Avatar answered Sep 26 '22 18:09

Richard Adams


I was running into the same issue, and finally I did Product->Clean within XCode, and it solved my problem.

like image 28
lukiller Avatar answered Sep 26 '22 18:09

lukiller


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

like image 45
Pratik Gujarati Avatar answered Sep 25 '22 18:09

Pratik Gujarati


In my case, I was creating actions for a few buttons, and I accidentally made an outlet, instead of an action. I just deleted the @IBOutlet line.

My error was:

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

Again, in my case, I found my solution from:

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 :)

Hope this helps!

like image 24
Rickybobby Avatar answered Sep 22 '22 18:09

Rickybobby