web-dev-qa-db-ja.com

setValue:forUndefinedKey:このクラスはキーのキー値コーディングに準拠していません

サポートチケットを表示するためにログインを作成しています。最初のビューはチケットビューです。ログインしていない場合は、ログイン画面に移動します。しかし、私はこれを受け取ります:

Support [3209:18e03] *キャッチされない例外 'NSUnknownKeyException'によるアプリの終了、理由: '[setValue:forUndefinedKey:]:このクラスはキーLoginScreenのキー値コーディングに準拠していません。*

まずスローコールスタック:(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:呼び出された例外をスローして終了

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

および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>
70
user1890328

このような不可解な例外は、多くの場合、汚れたxibファイルの結果です。 xcodeでxibを開き、[ファイルの所有者]を選択し、[接続インスペクター](右上矢印)をクリックして、すべてのアウトレットを一度に表示します。アウトレットがないことを示す!sを探します。

263
AlexWien

Interface Builderで接続を確認します。おそらく存在しないIBOutletまたはIBActionを参照しています。

37

Look "!"

みんなありがとう。あなたの助けを借りてこの問題を解決しました。したがって、このスクリーンショットが同じ問題を抱えている人に役立つことを願っています。

32
bureaucoconut

Xcodeのブレークポイントタブに移動します。下部のボタンを使用して、例外ブレークポイントを追加します。これで、setValue:forKey:および関連するスタックを呼び出しているコードが表示されます。運が良ければ、問題の原因を突き止めることができます。

クラスがLoginScreenであることは奇妙ですが、エラーは誰かが「LoginScreen」をキーとして使用していると言っています。 LoginScreen.mがターゲットの一部であることを確認してください。

enter image description here


脚注:Swiftを使用すると、クラスの名前を変更にすると一般的な問題が発生します(したがって、コード内のすべての場所で名前を変更します)。ストーリーボードはこれに苦労し、通常はre-dragそのクラスに関係する接続が必要です。特に、右側のIdentityInspectorタブで使用されるクラスの名前を再入力。 (図の例では、意図的にクラス名のスペルを間違えました。しかし、クラスの名前を変更すると同じことがよく起こります; IdentityInspectorで一見正しいように見えますがオートコンプリートで準備完了です。)

24
Graham Perks

カスタムTableCellの作成でも同様の問題がありました。問題は、FileOwnerをカスタムクラスに設定してから、コンセントを接続したことです。

FileOwnerはNSObjectのままにしてください。

22
Milos Zikic

私はこれを持っていて、すべてを見て、問題は見ませんでしたが、最終的にCleanを試し、Derived Dataをクリアすることを思い出しました!

7
Chad Parker

私も同様の問題を抱えていましたが、initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNilを使用して、渡された文字列としてクラスの名前を明示的に使用していました(不正な形式です!)。

わずかに異なる名前を使用してView Controllerを削除して再作成しましたが、メソッドで指定された文字列を変更するのを怠ったため、古いバージョンがまだ使用されていました-それはゴミ箱にありました!

2つのnilパラメーターをinitWithNibName:bundleに渡しています:メソッドの悪い習慣(つまり、安全でない、または遅い)?

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

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

これが誰かの助けになることを願っています!

2
RndmTsk

このエラーは別のものです!

ここに私がそれを修正した方法があります。 Xcodeバージョン6.1.1とSwiftを使用しています。アプリが次の画面にジャンプするためにセグエを実行しようとするたびに、このエラーが発生しました。ここで私がやったこと。

  1. ボタンが正しいアクションに接続されていることを確認しました(これは問題ではありませんでしたが、確認しておくと良いでしょう)。
  2. ボタンに、誤って作成した可能性のある追加のアクションやアウトレットがないことを確認してください。 (これは問題ではありませんでしたが、まだ確認するのが良いです)
  3. ログを確認し、次の画面のすべてのボタンに正しいアクションがあることを確認し、セグエがある場合は、一意の識別子があることを確認してください。 (これが問題でした)
    • セグエの1つに一意の識別子がありませんでした
    • ボタンの1つには、誤って作成したアクションと2つのアウトレットがありました。

追加のアウトレットを削除し、次の画面のセグエが一意の識別子を持っていることを確認します。

乾杯、

2
Ronaldoh1

StoryBoradを使用しておらず、プロジェクトプロパティ->展開情報->メインインターフェイスがメインXibの名前だったため、この問題が発生しました。

メインインターフェイスの値を削除し、問題を解決しました。

1

異なるstorybordファイルがあり、ヘッダーファイルにアウトレットが作成されたアウトレット参照がある場合は、ファイル所有者を右クリックして接続を削除するだけです。

ファイルの所有者->右クリック->向こうの不要な接続を削除します。

明確な説明のためにこれを通過してください。 これはどういう意味ですか?「 'NSUnknownKeyException'、理由:…このクラスはキーXのキー値コーディングに準拠していません」

には2つの機能がないためです

@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
0
YannSteph

今日、この同じ問題に遭遇しました。 この回答では のように、問題は汚れたxibでした。私の場合、汚れたxibは、関連付けられているView Controller以外の何かによってロードされていたxibを更新した結果でした。

Xcodeを使用すると、新しいアウトレットを作成してデータを設定し、正しいView Controllerのソースに明示的に接続しても、ファイルの所有者に接続できます。 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>

アプリを実行すると、同じnot key value coding-compliantエラーでクラッシュしました。この問題を修正するために、Interface BuilderのFile's Ownerからアウトレットを削除し、アシスタントエディターのコードではなく、左側のアウトラインのView Controllerオブジェクトに明示的に接続しました。

0
lambmj

カスタムビュークラスを作成するときに同様のエラーが発生しました。これは、何らかの方法でアウトレットの1つがXIBファイルに2回接続されたためです(最初にコントロールをコードに直接ドラッグしましたが、後者のコントロールはファイルの所有者)。 XIBファイルを開いてそのうちの1つを削除した後、すべてが正常に機能しました。これがお役に立てば幸いです。

0
Ray

私の場合、私はIBOutlet UILabel * description .hにあり、黄色の/!\- "will not synthetic"、 覚えている限り。ダンノそれは何で、なぜこのラベルだけなのか。

しかし、上記のようなクラッシュとエラーが発生しました。 * descriptionを削除し、* description2を再作成します。結果としてクラッシュしません。

0
djdance

私の場合、nibを登録するコレクションビューヘッダーの呼び出しをクラスの登録に切り替えました。それはそれを修正しました。

0
cynistersix

これはすべての場所のPickerViewで取得しました。エラーメッセージは、メッセージの最初に「queuePicker」の問題の名前を付けていました。これは、コンポーネントを追加して元のNSArrayの名前をqueuePicker以外に変更した後、有効ではなくなった以前の参照アウトレットが原因でした。 StoryBoardオブジェクトをCNTLキーを押しながらクリックすると、接続が提供されます。アウトレットの参照でqueuePickerのViewControllerの横にある「x」をクリックして、新しい接続を作成し、ビオラでクラッシュしなくなりました。

0
Russell Crow

おそらく、alertViewのキーに値を設定していますが、これは許可されていません。キーはこの場合LoginScreenです。 setValue()への呼び出しが表示されないため、コード内のどこかにあると想定します。

0
Matt

これは通常、何かが@ property "givenName"にアクセスしようとしていることを意味します。

Interface Builder(IB)で何かをしていた場合、通常の原因は次のいずれかです。

  1. クラスからそのプロパティを削除しましたが、まだIBのフックアップを削除していません
  2. または:ファイルの所有者オブジェクトが間違ったクラスに設定されています(プロパティを確認します-使用しているxcodeのバージョンによって異なります
    • クラス名を見つけるには、そのセットとして。あなたはおそらくNIBファイルをコピー/貼り付けし、NIBのこのフィールドを変更していません)、そのクラスのアウトレットを接続しましたが、実際のファイルの所有者は別のものです
0
Xar E Ahmer

これは、次のシナリオで私に起こりました。

ワークスペースに2つ目のプロジェクトを作成し、テンプレートに「シングルビューアプリケーション」を選択しました。

次に、Interface Builder(メインのiPhoneストーリーボード)に行き、UISwitchをメインビューに追加し、IBOutletIBAction-valueChanged:)。

起動時に、質問に記載されている例外でアプリがクラッシュします。ビューからスイッチを削除すると、機能します。

注意深く調べた結果、同じワークスペース内の別のプロジェクトのViewController.hへの接続をコントロールドラッグしたことに気付きました。 Interface BuilderのAssistant Editorの「自動」セット(別名Tuxedoチェストアイコン)は、(適切な名前の)間違ったファイルを「カウンターパート」として選択しました。

これが誰かに役立つことを願っています。特に、「シングルビューアプリケーション」プロジェクトテンプレートと「SpriteKitゲーム」プロジェクトテンプレート(私の場合)の両方が「ViewController」というデフォルトのビューコントローラークラスを作成するからです。

0
Nicolas Miari