77

I'm creating a login to view support tickets. The first view is the ticket view, and if you're not logged in pushes you to the login screen. However I receive this:

Support[3209:18e03] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key LoginScreen.' *

First throw call stack: (0x1f17012 0x1634e7e 0x1f9ffb1 0x10e1711 0x1062ec8 0x10629b7 0x108d428 0x7990cc 0x1648663 0x1f1245a 0x797bcf 0x65ce37 0x65d418 0x65d648 0x65d882 0x669235 0x8683d2 0x6664f3 0x666777 0x6667b7 0x9d1fe2 0x9c3ad9 0x65e422 0x2b15 0x65f753 0x65fb2f 0x661286 0x65fe3f 0x592910 0x592895 0x5926e5 0x1edfafe 0x1edfa3d 0x1ebd7c2 0x1ebcf44 0x1ebce1b 0x22aa7e3 0x22aa668 0x57c65c 0x1f0d 0x1e35) libc++abi.dylib: terminate called throwing an exception

Here is my code for LoginScreen.m

#import "UIAlertView+error.h"
#import "LoginScreen.h"
#import "API.h"
#include <CommonCrypto/CommonDigest.h>

#define sayWhat @"REMOVEDFORSECURITY"


@implementation LoginScreen

-(void)viewDidLoad {
    NSLog(@"Found me!");
    [super viewDidLoad];


    //focus on the username field /show keyboard
    [fldUsername becomeFirstResponder];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }

    -(IBA

ction)btnLoginRegisterTapped:(UIButton*)sender {
    if (fldUsername.text.length < 4 || fldPassword.text.length < 4){
        [UIAlertView error:@"Enter username and password over 4 chars each."];
        return;
    }

    //very basic encryption called "salting"
    NSString* saltedPassword = [NSString stringWithFormat:@"%@%@", fldPassword.text, sayWhat];

    //prep the hashed storage
    NSString* hashedPassword = nil;
    unsigned char hashedPasswordData[CC_SHA1_DIGEST_LENGTH];

    //actually hash this
    NSData *data = [saltedPassword dataUsingEncoding: NSUTF8StringEncoding];
    if (CC_SHA1([data bytes], [data length], hashedPasswordData)){
        hashedPassword = [[NSString alloc] initWithBytes:hashedPasswordData length:sizeof(hashedPasswordData) encoding:NSASCIIStringEncoding];
        } else {
            [UIAlertView error:@"Password can't be sent"];
                return;
        }

    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
        fldUsername.text, @"username",
                                   hashedPassword, @"password", nil];
    //here is the web call finally!
    [[API sharedInstance] commandWithParams:params
                               onCompletion:^(NSDictionary *json){
        //returned result
       NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0];

        if([json objectForKey:@"error"]==nil && [[res objectForKey:@"userid"] intValue]> 0) {
                                       //success
        } else {
                                       //error'
        [UIAlertView error:[json objectForKey:@"error"]];
                                   }

    }];


}
@end

and LoginScreen.h

#import <UIKit/UIKit.h>

@interface LoginScreen : UIViewController {
//the login form fields
IBOutlet UITextField* fldUsername;
IBOutlet UITextField* fldPassword;

}

//action for when either button is pressed
-(IBAction)btnLoginRegisterTapped:(id)sender;

@end


    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2844" systemVersion="12C60" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="A8c-eR-geg">
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1930"/>
    </dependencies>
    <scenes>
        <!--Tickets View - View Tickets-->
        <scene sceneID="aIJ-Wx-2Yy">
            <objects>
                <viewController title="View Tickets" id="T0P-Bi-31w" customClass="TicketsView" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" id="4zZ-I2-ltX">
                        <rect key="frame" x="0.0" y="64" width="320" height="504"/>
                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                        <subviews>
                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="You Made It" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Fbu-Sr-Mgf">
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                        </subviews>
                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                        <constraints>
                            <constraint firstItem="Fbu-Sr-Mgf" firstAttribute="top" secondItem="4zZ-I2-ltX" secondAttribute="top" constant="138" id="QBp-qM-fKP"/>
                            <constraint firstItem="Fbu-Sr-Mgf" firstAttribute="leading" secondItem="4zZ-I2-ltX" secondAttribute="leading" constant="115" id="goO-5h-RZK"/>
                        </constraints>
                    </view>
                    <navigationItem key="navigationItem" id="vu4-JX-C3v"/>
                    <simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
                    <connections>
                        <segue destination="TOB-FA-Ss4" kind="modal" identifier="ShowLogin" id="dJH-ge-8CV"/>
                    </connections>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="aSa-2G-5fx" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="-518" y="-841"/>
        </scene>
        <!--Login Screen - Login-->
        <scene sceneID="6iZ-QL-7ID">
            <objects>
                <viewController title="Login" id="TOB-FA-Ss4" customClass="LoginScreen" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" id="w9e-4U-cwC">
                        <rect key="frame" x="0.0" y="64" width="320" height="504"/>
                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                        <subviews>
                            <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Blue Label Hosting Login" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="SuD-JI-L2T">
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Username" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="NeI-zB-U8Y">
                                <constraints>
                                    <constraint firstAttribute="height" constant="31" id="BlH-cG-Jdh"/>
                                    <constraint firstAttribute="width" constant="208" id="Osb-tj-fjn"/>
                                </constraints>
                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                <textInputTraits key="textInputTraits"/>
                            </textField>
                            <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Password" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="4Fi-NX-kli">
                                <constraints>
                                    <constraint firstAttribute="height" constant="31" id="X3j-X2-ton"/>
                                </constraints>
                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                <textInputTraits key="textInputTraits" secureTextEntry="YES"/>
                            </textField>
                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5o5-83-KbW">
                                <constraints>
                                    <constraint firstAttribute="height" constant="36" id="Afu-6h-uru"/>
                                    <constraint firstAttribute="width" constant="161" id="Ef5-df-Jmp"/>
                                </constraints>
                                <fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
                                <state key="normal" title="Login">
                                    <color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
                                    <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
                                </state>
                                <state key="highlighted">
                                    <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                </state>
                                <connections>
                                    <action selector="btnLoginRegisterTapped:" destination="w9e-4U-cwC" eventType="touchUpInside" id="Wgb-L8-sAJ"/>
                                </connections>
                            </button>
                        </subviews>
                        <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
                        <constraints>
                            <constraint firstItem="NeI-zB-U8Y" firstAttribute="top" secondItem="SuD-JI-L2T" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="0Pv-zM-WId"/>
                            <constraint firstItem="4Fi-NX-kli" firstAttribute="top" secondItem="NeI-zB-U8Y" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="2Sw-m8-LND"/>
                            <constraint firstItem="4Fi-NX-kli" firstAttribute="trailing" secondItem="NeI-zB-U8Y" secondAttribute="trailing" type="default" id="88O-VQ-qut"/>
                            <constraint firstItem="SuD-JI-L2T" firstAttribute="centerX" secondItem="NeI-zB-U8Y" secondAttribute="centerX" type="default" id="Qu9-PG-YWz"/>
                            <constraint firstItem="4Fi-NX-kli" firstAttribute="centerX" secondItem="5o5-83-KbW" secondAttribute="centerX" type="default" id="RAm-sI-Z3u"/>
                            <constraint firstItem="5o5-83-KbW" firstAttribute="top" secondItem="w9e-4U-cwC" secondAttribute="top" constant="128" id="UTG-NS-bx4"/>
                            <constraint firstItem="SuD-JI-L2T" firstAttribute="top" secondItem="w9e-4U-cwC" secondAttribute="top" constant="20" symbolic="YES" type="default" id="iaC-Ex-EBa"/>
                            <constraint firstItem="SuD-JI-L2T" firstAttribute="centerX" secondItem="w9e-4U-cwC" secondAttribute="centerX" type="default" id="oWP-Gp-Pi5"/>
                            <constraint firstItem="4Fi-NX-kli" firstAttribute="leading" secondItem="NeI-zB-U8Y" secondAttribute="leading" type="default" id="oxE-WD-fVc"/>
                        </constraints>
                        <connections>
                            <outlet property="fldPassword" destination="4Fi-NX-kli" id="4eb-YW-8YI"/>
                            <outlet property="fldUsername" destination="NeI-zB-U8Y" id="Ds4-XS-iqW"/>
                        </connections>
                    </view>
                    <simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="FL3-Yk-JbH" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="-84" y="-349"/>
        </scene>
        <!--Navigation Controller-->
        <scene sceneID="fJ6-wq-4Tj">
            <objects>
                <navigationController id="A8c-eR-geg" sceneMemberID="viewController">
                    <toolbarItems/>
                    <navigationBar key="navigationBar" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="bnk-dD-E4j">
                        <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
                        <autoresizingMask key="autoresizingMask"/>
                    </navigationBar>
                    <nil name="viewControllers"/>
                    <connections>
                        <segue destination="T0P-Bi-31w" kind="relationship" relationship="rootViewController" id="3jA-WY-c3V"/>
                    </connections>
                </navigationController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="lTO-TW-owb" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="-971" y="-910"/>
        </scene>
    </scenes>
    <classes>
        <class className="LoginScreen" superclassName="UIViewController">
            <source key="sourceIdentifier" type="project" relativePath="./Classes/LoginScreen.h"/>
            <relationships>
                <relationship kind="action" name="btnLoginRegisterTapped:"/>
                <relationship kind="outlet" name="fldPassword" candidateClass="UITextField"/>
                <relationship kind="outlet" name="fldUsername" candidateClass="UITextField"/>
            </relationships>
        </class>
        <class className="NSLayoutConstraint" superclassName="NSObject">
            <source key="sourceIdentifier" type="project" relativePath="./Classes/NSLayoutConstraint.h"/>
        </class>
        <class className="TicketsView" superclassName="UIViewController">
            <source key="sourceIdentifier" type="project" relativePath="./Classes/TicketsView.h"/>
        </class>
    </classes>
    <simulatedMetricsContainer key="defaultSimulatedMetrics">
        <simulatedStatusBarMetrics key="statusBar"/>
        <simulatedOrientationMetrics key="orientation"/>
        <simulatedScreenMetrics key="destination" type="retina4"/>
    </simulatedMetricsContainer>
</document>
Monolo
  • 17,926
  • 16
  • 63
  • 102
user1890328
  • 1,162
  • 1
  • 12
  • 21
  • 3
    Make sure the `LoginScreen` outlet is set in your XIB – CodaFi Dec 09 '12 at 23:52
  • Where does this error occur. It seems like it's probably in the ticket view controller. If so, you should post that code instead of this. – rdelmar Dec 09 '12 at 23:59
  • 1
    such unexplainable exceptions are often a result from an unckean xib file. open the xib in xcode, click on ViewOwner and look at rhe outleds that are marked with an "!" – AlexWien Dec 10 '12 at 00:12
  • If it had worked for me I would have. It did not so I will not. – user1890328 Nov 18 '13 at 19:13
  • In my case. I didn't have missing outlets. Shift + command + K solved my problem. I cleaned my project and rebuilt. – Kiryl Belasheuski Oct 02 '15 at 09:07
  • I had the same issue but fixed it in different way. My project has different build configuration (pointing to different environment) which creates build with different bundle identifier. Somehow one of my cell's module (in Interface builder) was set to specific bundle identifier. I just set it to current-module to make it work. Setting none did not work. – deepax11 May 19 '16 at 10:54

20 Answers20

273

Such inexplicable exceptions are often a result of an unclean xib file. Open the xib in xcode, select File's Owner and click on the "Connection Inspector" (upper right arrow), to see all outlets at once. Look for !s which indicates a missing outlet.

AlexWien
  • 27,247
  • 5
  • 48
  • 78
  • so far nothing. I'm using storyboards and not individual xib's. I changed it so the login screen was the first view loaded just to test and still same error. I've edited my post to show the XML of the storyboard. – user1890328 Dec 11 '12 at 02:21
  • @user1890328 your XML does not show in the question – Gabriele Petronella Dec 11 '12 at 02:28
  • @GabrielePetronella I went ahead and updated it, you should see it now. Graham I"ll do that know and report back shortly. Thanks everyone for the help so far! – user1890328 Dec 11 '12 at 02:33
  • The breakpoint is brining me to the main.m to be exact: return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); I'm also getting this now that i'm loading the LoginScreen view: Storyboard.storyboard: Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:. – user1890328 Dec 11 '12 at 02:50
  • 12
    AlexWien I love you. For others that might be stuck, you can see all connections if you go storyboard>view_you_are_crashing_on, and then click connections inspector, which is the little right arrow at the very top-right edge of the screen. My problem was that I had deleted objects/changed their names, but the connections still existed, with the old names. – Mirror318 Dec 23 '13 at 07:27
  • 3
    If you're backing up your view with a custom class, also make sure that you do not link it with `File's Owner`, but with the root of your view, e.g. your custom `UICollectionViewCell`. – Dennis Sep 25 '14 at 08:40
  • Superb!! catch.. Thank you for sharing this information. – swiftBoy Jan 08 '15 at 10:27
  • @Dennis, I had forgotten about that with cells. Been doing android dev lately and this went totally out of me head. :-P One other note...if you HAD used `File's Owner` by mistake and corrected it, but are still getting errors, check the XML. IB sometimes will not show the connections if they were previously there and you removed them, but they might still be in the XML. I just had this happen to me and waste an hour or so of my life. Using xcode 7.2.1. – stuckj Mar 17 '16 at 19:52
  • Exactly this was happening to me and fixing the `!` outlet resolved the issue. I really wonder how you @AlexWien discover the relation between those things! – Sebastian Sastre Aug 01 '16 at 00:26
  • In my case I found the problem was an outlet and an action with the same name on the same object (NavButtonBar). I had intended to add an action but instead added an outlet. I then deleted the outlet code and added an action but the conflict remained. I fixed it by checking the connections on the button and deleting the outlet. – markhorrocks Dec 05 '16 at 04:55
37

Check your connections in Interface Builder. You're probably referring to a non existent IBOutlet or IBAction.

John Topley
  • 107,187
  • 45
  • 188
  • 235
Gabriele Petronella
  • 102,227
  • 20
  • 204
  • 227
33

Look "!"

Thanks guys. I solved this problem through your help. So, I hope this screenshot helpful to person who have same problem.

bureaucoconut
  • 711
  • 7
  • 15
26

Go to Xcode's breakpoints tab. Use the button at the bottom to add an exception breakpoint. Now you'll see what code is invoking setValue:forKey: and the associated stack. With luck that'll point you straight at the problem's source.

Odd that your class is LoginScreen, yet the error is saying someone is using "LoginScreen" as a key. Check that LoginScreen.m is part of your target.

enter image description here


Footnote: with Swift a common problem arises if you change the name of a class (so, you rename it everywhere in your code). Storyboard struggles with this, and you usually have to re-drag any connections involving that class. And in particular, re-enter the name of the class anywhere used in IdentityInspector tab on the right. (In the picture example I deliberately misspelled the class name. But the same thing often happens when you rename a class; even though it's seemingly correct in IdentityInspector, you need to enter the name again; it will correctly autocomplete and you're good to go.)

Fattie
  • 30,632
  • 54
  • 336
  • 607
Graham Perks
  • 21,623
  • 8
  • 56
  • 79
  • i typed new class name before, it not worked, so i pull down selector and select that class (the same, of course) by mouse click. Now it works. – djdance Jan 17 '16 at 13:57
  • 1
    OMG!! Thank you so much!! I have been struggling with this issue for days and your Footnote helped. I renamed the class and in identity inspector everything looked right but as you said I had to re-enter the name of class in IdentityInspector and things worked. Wasted so much time debugging and looking up for this issue – adubey Oct 07 '16 at 05:07
  • Thank you, this was driving me nuts. Both your suggestion on exception breakpoints and re-entering the name of the table cell helped me locate and fix the issue. Storyboards in iOS can be really, really finicky. – James Dobson Oct 18 '16 at 15:52
  • An exception break point indicated that my VC's class "didn't exist." What?! Turns out the VC's implementation file's "Target Membership" (in Xcode window > Utility Pane > File Inspector) was not checked. Checked to add the file to the current target and everything worked. – Code Roadie Mar 28 '18 at 23:18
23

I had similar issue with creating custom TableCell. The issue was that I set FileOwner to my custom class and then connected outlets.

FileOwner should remain NSObject.

Milos Zikic
  • 251
  • 2
  • 7
6

I had this and looked over everything and didn't see any problems, but eventually remembered to try Clean and clear Derived Data and that solved it!

Chad Parker
  • 121
  • 2
  • 5
2

I had a similar problem, but I was using initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil explicitly using the name of the class as the string passed (yes bad form!).

I ended up deleting and re-creating the view controller using a slightly different name but neglected to change the string specified in the method, thus my old version was still used - even though it was in the trash!

I will likely use this structure going forward as suggested in: Is passing two nil paramters to initWithNibName:bundle: method bad practice (i.e. unsafe or slower)?

- (id)init
{
    [super initWithNibName:@"MyNib" bundle:nil];
    ... typical initialization ...
    return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    return [self init];
}

Hopefully this helps someone!

Community
  • 1
  • 1
RndmTsk
  • 1,594
  • 2
  • 10
  • 12
  • You could also use `NSStringFromClass([self class])` instead of `@"MyNib"` to avoid re-typing the class name every time you want to use this construct. – RndmTsk Feb 04 '15 at 21:45
2

This error is something else!

Here is how i Fixed it. I'm using xcode Version 6.1.1 and using swift. I got this error every time my app tried to perform a segue to jump to the next screen. Here what I did.

  1. Checked that the button was connected to the right action.(This wasn't the problem, but still good to check)
  2. Check that the button does not have any additional actions or outlets that you may have created by mistake. (This wasn't the problem, but still good to check)
  3. Check the logs and make sure that all the buttons in the NEXT SCREEN have the correct actions, and if there are any segues, make sure that they have a unique identifier. (This was the problem)
    • One of the segues did not have a unique identifier
    • One of the buttons had an action and two outlets that I created by mistake.

Delete any additional outlets and make sure that you the segues to the next screen have unique identifiers.

Cheers,

Ronaldoh1
  • 2,717
  • 2
  • 26
  • 39
  • 1
    It was #3. There was an issue in number in the next view controller. Adding the breakpoint on exception helps. – agarcian Dec 18 '16 at 22:33
1

I had this problem because I was not using StoryBorad, and on the project properties -> Deploy info -> Main interface was the name of the Main Xib.

I deleted the value in Main Interface and solved the problem.

Ronaldo Albertini
  • 1,098
  • 20
  • 19
  • 1
    I was craking my head with all kinds of things and I also did this, deleted it and it all works fine I'm on 6.1 – becker Oct 12 '16 at 03:13
0

I ran into a similar error when creating a custom view class, that was because somehow one of the outlet got hooked up twice in the XIB file(I think I initially control dragged the control directly to the code, but latter control dragged again from the File's owner). I opened the XIB file and remove one of them, after that everything worked fine. Hopefully this helps.

Ray
  • 15,087
  • 5
  • 26
  • 50
0

I got this one on a PickerView of all places. The error message was naming the problem with "queuePicker" at the first of the message. It was caused by a previous Referencing Outlet which was no long valid after I added a component and renamed the original NSArray something other than queuePicker. CNTL+click on your StoryBoard object gives you the connections. I clicked the "x" next to the ViewController for queuePicker in Referencing Outlets, made a new connection, and viola, no more crashes.

0

You're probably setting a value for a key in the alertView, which is not allowed. The key is in this case LoginScreen. I don't see any call to setValue(), so I assume it's somewhere else in the code.

Mani
  • 17,226
  • 13
  • 73
  • 97
mhrvth
  • 62
  • 1
  • 1
  • 7
0

I encountered this same problem today. As suggested in this answer, the problem was an unclean xib. In my case the unclean xib was the result of updating a xib that was being loaded by something other than the view controller it was associated with.

Xcode let me create and populate a new outlet and connected it to the file's owner even though I explicitly connected it to the source of the correct view controller. Here's the code generated by Xcode:

    <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="LoginViewController"]]>
        <connections>
            <outlet property="hostLabel" destination="W4x-T2-Mcm" id="c3E-1U-sVf"/>
        </connections>
    </placeholder>

When I ran my app it crashed with the same not key value coding-compliant error. To correct the problem, I removed the outlet from the File's Owner in Interface Builder and connected it explicitly to the view controller object on the left outline instead of to the code in the assistant editor.

Community
  • 1
  • 1
lambmj
  • 1,833
  • 2
  • 21
  • 27
0

This happened to me in the following scenario:

I created a second project in my workspace, chose "Single View Application" for the template.

I then went to Interface Builder (main iPhone storyboard), added a UISwitch to the main view, and connected it to the view controller through both an IBOutlet and an IBAction (-valueChanged:).

On launch, the app crashes with the exception mentioned in the question. If I remove the switch from the view, it works.

After careful inspection, I realized I control-dragged the connections into the ViewController.h of another project in the same workspace. The 'Automatic' set of Interface Builder's Assistant Editor (a.k.a Tuxedo chest icon) chose as "counterpart" the wrong file (with the right name).

Hope this helps someone, specially because both 'Single View Application' and 'SpriteKit Game' project templates (in my case) create a default view controller class called "ViewController".

Nicolas Miari
  • 15,044
  • 6
  • 72
  • 173
0

If you have different storybord files and if you have outlet references with out outlets creation in your header files then you just remove the connections by right clicking on files owner.

Files owner->Right click->remove unwanted connection over there.

Go through this for clear explanation. What does this mean? "'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X"

Community
  • 1
  • 1
0

This usually means that something is trying to access the @property "givenName".

If you were doing something with Interface Builder(IB), the usual cause is that you either:

  1. deleted that property from the class, but haven't deleted the hookups in IB yet
  2. OR: you have a File's Owner object set to the wrong class (check the properties - different depending which version of xcode you're using
    • to find the Class Name its set as. You probably copy/pasted a NIB file, and didn't change this field in the NIB), and you've hooked up an outlet for that class, but your actual File's Owner is something different
AndroidGeek
  • 30,803
  • 14
  • 212
  • 262
0

In my case I have IBOutlet UILabel *description in .h, it was with yellow /!\ - "will not synthesized", as I remember. Dunno what is it and why only this label.

But I got this crash and error like above. Deleted *description and recreate *description2. No crash in result.

djdance
  • 2,833
  • 23
  • 31
0

For me I switched a call for my collection view header where I was registering the nib to registering the class. That fixed it.

cynistersix
  • 1,215
  • 1
  • 16
  • 28
0

For is because is not have 2 function

@implementation CellTableView

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    return [self init];
}
- (void)awakeFromNib {
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
YannSteph
  • 9,590
  • 3
  • 49
  • 46
-1

I had to delete all objects and re-add them. This seemed to have fixed the issue.

user1890328
  • 1,162
  • 1
  • 12
  • 21