This class is not key value coding-compliant for the key

Hi,

I'm a beginner at C# and very new to iOS and Xamarin - but am teaching myself and making some progress towards my first app (a battle calculator for an iOS game). I have two issues which I have been unable to resolve on my own after hours of fiddling and scouring the web.

For my root controller I have a TabBarController which has 2 NavigationControllers and one standard ViewController set as its tabs. The page that is being loaded has several buttons of which I have one wired via an outlet to push a new ViewController onto the NavigationController in the first tab. Loading this up in the simulator has no problems. Deploying to my device throws me this exception:

Objective-C exception thrown. Name: NSUnknownKeyException Reason: [<screenAttacker 0x16593570> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key btnWall.

I've seen that this could be caused by setting a Main Interface in the info.plist and can confirm that both the iPad and iPhone sections are blank for this field.

Also this can be caused by outlets not being deleted correctly or objects being linked to outlets which no longer exist etc. I deleted all entries in the .h and .m files and removed all outlet connections (in deleted and re-added all buttons also) and created a fresh one.

The second (and I'm assuming unrelated) issue is warnings MT3005 & MT3006 - also only when deploying to device:

Warning MT3005: The dependency 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' of the assembly 'monotouch, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' was not found. Please review the project's references. (MT3005)

Warning MT3006: Could not compute a complete dependency map for the project. This will result in slower build times because Xamarin.iOS can't properly detect what needs to be rebuilt (and what does not need to be rebuilt). Please review previous warnings for more details. (MT3006)

Any help with these two issues would be greatly appreciated. Its driving me nuts. Below I've included that AppDelegate, ViewController and .h / .m files associated. Please let me know if you need any more info.

Cheers!

AppDelegate.cs:

`using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace KEBC
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{

    public static UIWindow window;
    public static UITabBarController rootTab;
    public static UINavigationController navAttacker;
    public static UINavigationController navDefender;
    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {

        window = new UIWindow (UIScreen.MainScreen.Bounds);

        screenAttacker screenAttacker = new screenAttacker ();
        screenDefender screenDefender = new screenDefender ();
        screenSummary screenSummary = new screenSummary ();
        navAttacker = new UINavigationController (screenAttacker);
        navDefender = new UINavigationController (screenDefender);
        navAttacker.Title = "Attacker";
        navDefender.Title = "Defender";
        screenSummary.Title = "Summary";


        rootTab = new UITabBarController ();
        UIViewController[] tabs = new UIViewController[] {
            navAttacker,
            navDefender,
            screenSummary
        };
        rootTab.ViewControllers = tabs;

        window.RootViewController = rootTab;

        // make the window visible
        window.MakeKeyAndVisible ();

        return true;
    }
}

}`

screenAttacker.cs:

`using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace KEBC
{
public partial class screenAttacker : UIViewController
{
static bool UserInterfaceIdiomIsPhone {
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}

    public screenAttacker ()
        : base (UserInterfaceIdiomIsPhone ? "screenAttacker_iPhone" : "screenAttacker_iPad", null)
    {
    }

    public override void DidReceiveMemoryWarning ()
    {

        base.DidReceiveMemoryWarning ();

    }

    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear (animated);
        this.NavigationController.SetNavigationBarHidden (true, animated);
    }

    public override void ViewWillDisappear(bool animated)
    {
        base.ViewWillAppear (animated);
        this.NavigationController.SetNavigationBarHidden (false, animated);
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        this.Title = "Attacker";
        btnWall.TouchUpInside += (sender, e) => {
            AppDelegate.navAttacker.PushViewController(new screenWall(), true);
        };

    }

}

}`

screenAttack.h:

`#import <Foundation/Foundation.h>

import <UIKit/UIKit.h>

@interface screenAttacker : UIViewController {
}

@property (retain, nonatomic) IBOutlet UIButton *btnWall;

@end`

screenAttacker.m:

`#import "screenAttacker.h"

@implementation screenAttacker

  • (void)dealloc {
    [_btnWall release];
    [super dealloc];
    }
    @end`

Posts

  • LucasBeristaynLucasBeristayn USMember

    Great! A clean worked for me!

  • HashTagItHashTagIt USMember

    I looked everywhere for this silly error. I even remade the xib's/controller. Error still appeared... and cmd+shift+k fixed everything.

  • NimbusHexNimbusHex USMember ✭✭

    I really wish I would have just done a search earlier on this, you just made my night. Thank you.

  • PoulaertQuentinPoulaertQuentin USMember

    It makes the trick for me, thanks

  • I get the same error message when trying to run my project inside the emulator.

    I tried:

    • Cleaning the projekt
    • Checked my outlets
    • Removed and reinstalled the app

    I still get this error, and I seem to find no solution at all.

    Help?

  • TylerBurkeTylerBurke AUMember

    Hi Jack,

    In my original post I said cleaning in Xcode would do the trick, while this may actually work for some people (based on posts above), I did actually mean to say doing a clean in Xamarin.

    Have you tried cleaning the project in both IDE's?

    Cheers

  • adlairadlair MXXamarin Team Xamurai

    Jack, have you tried to delete the folder directly? Sometimes cleaning is not enough. If you tried cleaning the project on XCode or Xamarin and doesn't works, maybe you need try delete the bin and obj folders.

    This error is thrown when you change or remade the xib file.

    Cheers!

  • diegoxleondiegoxleon ESMember ✭✭
    edited March 2015

    I´ve been about 2 hours trying to fix this annoying error.
    Cleaning in Xamarin project was not enough. I had to delete obj and bin folders as adlair pointed out
    Thanks guys

  • MarcovanZuylenMarcovanZuylen NLUniversity

    OK ran into this problem multiple times, with multiple projects. All the solution mentioned here did not solve my problem.

    As far as I can understand; the problem occurs when a new view is created on the storyboard and you bind a new class that inherits UIViewController. So basically you bind a new viewcontroller to your view. What happens, is that (in my case) a designer class is autogenerated next to my viewcontroller classes. This should happen, but what also happens is that the annotation is created 2 times. That creates the issue. (Tip; in order to see the designer class, make sure you click on show all files and include the designer class into your project).

    The fix, was to delete the annotation in the non-designer class objects. And clean the project after.

    I am working in VisualStudio 2015RC+Windows7, on a macbook air, with parallels

    Sorry for any typos, as English is not my native language....

  • BeNRivBeNRiv USMember

    I am facing the same problem, using Visual Studio 2013

    With the main Menu, Build > Clean gets fixed

  • BryanBanksBryanBanks USMember
    edited February 2016

    Had the same problem. Tried clean (VS 2013), deleting bin+obj folders, etc. I knew it was a code problem b/c app would run fine on my iPod touch, but fail on iPad (and I was differentiating the code slightly between the two). Found that when I reverted to an older version using source control it worked.
    Anyways, long story short, I went through the code revisions until I found the issue. I had added a line to my info.plist with the following:
    < key >NSMainNibFile~ipad< /key > < string > Blank< /string >
    It's probably something I found online and put in when I was trying to fix some other problem. Anyways, my guess is you won't have the exact same issue, but if all else fails, check your info.plist.

  • ChrisReidChrisReid USMember

    Awesome, build clean fixed it, but had to clean project, not solution.

  • NjalEideNjalEide NOMember ✭✭
    edited September 2016

    @BryanBanks said:
    Had the same problem. Tried clean (VS 2013), deleting bin+obj folders, etc. I knew it was a code problem b/c app would run fine on my iPod touch, but fail on iPad (and I was differentiating the code slightly between the two). Found that when I reverted to an older version using source control it worked.
    Anyways, long story short, I went through the code revisions until I found the issue. I had added a line to my info.plist with the following:
    < key >NSMainNibFile~ipad< /key > < string > Blank< /string >
    It's probably something I found online and put in when I was trying to fix some other problem. Anyways, my guess is you won't have the exact same issue, but if all else fails, check your info.plist.

    I wasted two entire days on this. Don't know how it happened, but Xamarin found it smart to add the two lines below to info.plist :
    < key >NSMainNibFile< /key >
    < string >MainView< /string >

    After that no outlets would work whatever I did, and I tried so many different things it is unreal. Had upgraded Xamarin to latest build on Windows/OS X, upgraded OS X to Sierra and XCode to latest version. When all else failed I tried to roll-back the upgrades, but no luck What a waste of time. All I had to do was remove those two lines.

    Now I have to do the upgrades again. Arghhh....

  • VendpagoPd7VendpagoPd7 USMember

    Tried a bunch of different things (cleaning the project, deleting the bin/obj folder, checking my info.plist file) but the only thing that solved was to the delete the newly added ViewController that was giving me a headache and creating a new one with a different name.

  • JaredFairlessJaredFairless USMember

    I had this error for a while within a viewcontroller and an inheriting table view and Cleaning the project( command>Shift>K) didn't help, but I corrected the issue in the viewcontroller when I opened the viewcontroller.designer.cs and noticed that the name of the table view was next to the the namespace of the viewcontroller it was inheriting from and once I deleted the name of the table view the issue went away.

    I'm not sure how or why the name was added in the designer by xamarin, but none the less the issue was resolved.

  • KyleOlsonKyleOlson USMember

    I've had storyboards that would give me this error after cleaning/rebuilding. When I look at the designer.cs file, I see the outlets are missing/incomplete. Essentially the desiger.cs file has stopped updating.

    The easy but sloppy fix I found is to add an event to some random event handler to a View for the problematic View Controller. This regenerates the designer.cs file for the View Controller, adding the missing outlets.

  • danielgmontdanielgmont Member

    I had to open de .storyboard file and look for anything that should't be there and delete it on tag's... that's works for me...

  • JoshuaTantonJoshuaTanton USMember ✭✭

    For my case I was calling (CustomTableViewCell)Nib.Instantiate(null, null)[0]; that was causing this error.
    I was working with some XIB files for these custom cells which I hadn't used since I inherited the project. They were made previously for use cases that I didn't need to implement until now. I couldn't figure out why these cells (4 of 6) were failing while the cells I was always using previously (2 of 6) would not fail.
    Turns out the previous developer had a value for the Module property. Erasing this value allowed the instantiate to work without error.

  • ziggyziggy Member ✭✭
    edited February 27

    ERROR: This class is not key value coding-compliant for the key

    So I got this error message while doing the Xamarin.IOS Class [IOS110]. I created a TableView Controller in the designer and ran the app and it displays the empty table view. Next was to add code for the RowsInSection and GetCell methods which I did. Upon running I got the error "this class is not key value coding compliant for the key".

    I tried to fix it by doing a clean build and even deleting the bin and obj folders. Nothing worked. Last resort, I tried to delete the tableview controller and re-create a new one.

    Interesting enough, on my first try to delete the tableview controller "something" got deleted - but the whole table view controller did not get deleted. I ran the simulator and the tableview displayed.

    The reason that I put a "something" was deleted was because I went back to the storyboard and tried to delete the tableview controller and this time around the whole thing was deleted. So something was deleted during the first attempt which seems to be the tableview on top of the tableview controller.

    The issue is, the data was displayed even when the tableview was actually deleted. The problem is you would have to add the tableview back because you need it to change its properties such as background colour. So I clicked the undo button again for tableview to go back but it wont compile anymore. So I had to go to the properties of the tableview, change its name for the designer to re-write the designer.cs file. from there everything worked.

    this is very weird

  • CsabaAntalGolubovCsabaAntalGolubov USMember ✭✭

    This error was occured in my project because I have made two outlets for a particular view in my controller, and I have deleted the old one by hand from the .h file in the assistant editor. I had to right click on the view (the error message tells you which view has the missing outlet), and in the Outlet section, I deleted the old one.

    And after all of this, I am ALWAYS forgetting about: each ViewController must have the constructor that has the "IntPtr handle" parameter. Wish Xamarin Team will fix this issue once.

Sign In or Register to comment.