Ios 使用NSC检查文本字段中的值(用于登录)

Ios 使用NSC检查文本字段中的值(用于登录),ios,objective-c,xcode,Ios,Objective C,Xcode,我是IOS的超级新手。我正在做一个登录功能。按下登录按钮时,应用程序应检查存储器中的文本。然后,如果check status返回true,则应更改为第二个VC。我当前有一个带有标识符的ViewController到ViewController序列。我尝试了带标识符的执行序列,但它不起作用。(不改变场景,也不显示警报。) 这是登录页面。 #进口 @interface LoginPage : UIViewController @property (strong, nonatomic) IBOutle

我是IOS的超级新手。我正在做一个登录功能。按下登录按钮时,应用程序应检查存储器中的文本。然后,如果check status返回true,则应更改为第二个VC。我当前有一个带有标识符的ViewController到ViewController序列。我尝试了带标识符的执行序列,但它不起作用。(不改变场景,也不显示警报。)

这是登录页面。 #进口

@interface LoginPage : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *usernameField;
@property (strong, nonatomic) IBOutlet UITextField *passwordField;
- (IBAction)LoginTapped:(id)sender;

- (IBAction)SignupTapped:(id)sender;
@end
登录名是.m

#import "LoginPage.h"
#import "Home.h"
@implementation LoginPage

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)LoginTapped:(id)sender {

    NSMutableDictionary *infodictionary =[[NSMutableDictionary alloc] init];
    [infodictionary setObject:@"1" forKey:@"rose"];
    [infodictionary setObject:@"2" forKey:@"cathy"];
    [infodictionary setObject:@"3" forKey:@"corey"];
    if ([_passwordField.text isEqualToString:[infodictionary objectForKey: _usernameField.text]]){
 //       Home *home = [[Home alloc] init];
        [self performSegueWithIdentifier:@"ToHome" sender:self];
    }

}

- (IBAction)SignupTapped:(id)sender {
    NSString *_NAME = [NSString alloc];
    NSString *_PASS = [NSString alloc];
    _NAME=  _usernameField.text;
    _PASS = _passwordField.text;
       }
@end
刺激器让我终止了NSException类型的未捕获异常

2016-02-07 05:39:49.437 project_feature_login[8249:941926] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x7fb5f9c98300> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key passwordField.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000102b18f45 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000102592deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000102b18b89 -[NSException raise] + 9
    3   Foundation                          0x000000010215fa6b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
    4   UIKit                               0x000000010305004c -[UIViewController setValue:forKey:] + 88
    5   UIKit                               0x000000010327da71 -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x0000000102a59a80 -[NSArray makeObjectsPerformSelector:] + 224
    7   UIKit                               0x000000010327c454 -[UINib instantiateWithOwner:options:] + 1864
    8   UIKit                               0x0000000103056c16 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    9   UIKit                               0x0000000103057542 -[UIViewController loadView] + 178
    10  UIKit                               0x00000001030578a0 -[UIViewController loadViewIfRequired] + 138
    11  UIKit                               0x0000000103058013 -[UIViewController view] + 27
    12  UIKit                               0x0000000102f3151c -[UIWindow addRootViewControllerViewIfPossible] + 61
    13  UIKit                               0x0000000102f31c05 -[UIWindow _setHidden:forced:] + 282
    14  UIKit                               0x0000000102f434a5 -[UIWindow makeKeyAndVisible] + 42
    15  UIKit                               0x0000000102ebd396 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
    16  UIKit                               0x0000000102ec39c3 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1750
    17  UIKit                               0x0000000102ec0ba3 -[UIApplication workspaceDidEndTransaction:] + 188
    18  FrontBoardServices                  0x0000000105870784 -[FBSSerialQueue _performNext] + 192
    19  FrontBoardServices                  0x0000000105870af2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    20  CoreFoundation                      0x0000000102a45011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    21  CoreFoundation                      0x0000000102a3af3c __CFRunLoopDoSources0 + 556
    22  CoreFoundation                      0x0000000102a3a3f3 __CFRunLoopRun + 867
    23  CoreFoundation                      0x0000000102a39e08 CFRunLoopRunSpecific + 488
    24  UIKit                               0x0000000102ec04f5 -[UIApplication _run] + 402
    25  UIKit                               0x0000000102ec530d UIApplicationMain + 171
    26  project_feature_login               0x0000000102094a6f main + 111
    27  libdyld.dylib                       0x000000010523c92d start + 1
    28  ???                                 0x0000000000000001 0x0 + 1
)
2016-02-07 05:39:49.437项目-功能-登录[8249:941926]***由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:该类与密钥密码字段的键值编码不兼容。”
***第一次抛出调用堆栈:
(
0 CoreFoundation 0x0000000102b18f45例外预处理+165
1 libobjc.A.dylib 0x0000000102592deb objc_异常_抛出+48
2 CoreFoundation 0x0000000102b18b89-[N异常提升]+9
3基金会0x000 000 010215FA6B-[NSbObjs](NSKEY ValueCudid)SETValu:
4 UIKit 0x000000010305004c-[UIViewController设置值:forKey:+88
5 UIKit 0x000000010327da71-[UIRuntimeOutletConnection connect]+109
6 CoreFoundation 0x0000000102a59a80-[NSArray makeObjectsPerformSelector:+224
7 UIKit 0x000000010327c454-[UINib实例化所有者:选项:][1864
8 UIKit 0x0000000103056c16-[UIViewController\u loadViewFromNibNamed:bundle:][381
9 UIKit 0x0000000103057542-[UIViewController loadView]+178
10 UIKit 0x00000001030578a0-[UIViewController loadViewIfRequired]+138
11 UIKit 0x0000000103058013-[UIViewController视图]+27
12 UIKit 0x0000000102F351C-[UIWindow AddRootViewControllerServiceWifPossible]+61
13 UIKit 0x0000000102f31c05-[UIWindow\u setHidden:强制:][282
14 UIKit 0x0000000102f434a5-[UIWindow makeKeyAndVisible]+42
15 UIKit 0x0000000102ebd396-[UIApplication\u callInitializationDelegatesForMainScene:transitionContext:+4131
16 UIKit 0x0000000102ec39c3-[UIApplication\u在主场景中运行:transitionContext:completion:+1750
17 UIKit 0x0000000102ec0ba3-[UIApplication WorkspaceDiEndTransaction:][188
18 FrontBoardServices 0x0000000105870784-[FBSSerialQueue\u performNext]+192
19 FrontBoardServices 0x0000000105870af2-[FBSSerialQueue _performNextFromRunLoopSource]+45
20 CoreFoundation 0x0000000102a45011\uuu CFRUNLOOP\u正在调用\u OUT\u以执行\u功能\uuuu+17
21 CoreFoundation 0x0000000102a3af3c\uU CFRunLoopDoSources0+556
22 CoreFoundation 0x0000000102A3F3\uuu CFRunLoopRun+867
23 CoreFoundation 0x0000000102a39e08 CFRunLoopRunSpecific+488
24 UIKit 0x0000000102ec04f5-[UIApplication\u run]+402
25 UIKit 0x0000000102ec530d UIApplicationMain+171
26项目功能登录0x0000000102094a6f主+111
27 libdyld.dylib 0x000000010523c92d启动+1
28°?0x0000000000000001 0x0+1
)

寻求帮助

在验证if条件时,尝试使用
self.passwordField.text
而不是
\u passwordField.text
。同时检查界面生成器中密码字段的IBOutlet连接。为接口中的UIViewController设置的类必须是LoginPage

stacktrace似乎不涉及任何代码。我猜问题出在接口(NIB)上。您能确保IBActions和iBouts连接正确吗?@Vishnugondlekar我创建了一个cocoa文件,并将IBAction放在那里。@Vishnugondlekar我是否应该将它们添加到默认的Viewcontroller中?当您按下注册按钮时,问题会出现?