我正在创建一个登录以查看支持票证.第一个视图是ticket视图,如果您未登录,则会将您推到登录屏幕.然而,我收到了以下信息:

支持[3209:18e03]* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key 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

和登录屏幕.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>

推荐答案

这种莫名其妙的例外通常是不干净的xib文件造成的.

Objective-c相关问答推荐

iOS 7 表格视图无法自动调整内容插入

Objective-C:在字符串中查找数字

ARC下归零弱引用的集合

在objective-c中isa是什么意思?

为什么我不用 * 声明 NSInteger

在 viewDidAppear 之前无法正确设置框架

如何获取 NSArray 的最后一个对象

UICollectionView 标头未显示

Objective-C 中是否有一些文字字典或数组语法?

iOS 5 不允许将下载的数据存储在 Documents 目录中?

无法在 Interface Builder (Xcode 5) 中创建与子视图的出口连接

iPhone 键盘、完成按钮和 resignFirstResponder

从 NSMutableString 中删除最后一个字符

NSMutableArray 按顺序添加对象

在 UITableView 的 iOS 文档目录中列出保存的文件?

最大 CGFloat 值是否有常数?

如何获得设备的比例因子?

如何更新 Core Data 中的现有对象?

如何将 printf 与 NSString 一起使用

如何在 iOS 中创建自定义 UIActivity?