Ios 在if语句中,PushViewController会中断我的程序

Ios 在if语句中,PushViewController会中断我的程序,ios,objective-c,xcode,uinavigationcontroller,pushviewcontroller,Ios,Objective C,Xcode,Uinavigationcontroller,Pushviewcontroller,我已经在另一个类中创建了一个带有根视图控制器(登录屏幕)的导航控制器。当我点击登录按钮时,我想让它推到仪表板视图控制器。这是我的密码 - (IBAction)logInHit:(id)sender { if (passWord == true) { DashBoardViewController *dash = [[DashBoardViewController alloc] initWithNibName:@"DashBoardViewController" bund

我已经在另一个类中创建了一个带有根视图控制器(登录屏幕)的导航控制器。当我点击登录按钮时,我想让它推到仪表板视图控制器。这是我的密码

- (IBAction)logInHit:(id)sender {

    if (passWord == true) {
        DashBoardViewController *dash = [[DashBoardViewController alloc] initWithNibName:@"DashBoardViewController" bundle:nil];
        [self.navigationController pushViewController:dash animated:YES];
    }

    else if (passWord == false){
        UIAlertView *alert = [[UIAlertView alloc] init];
        [alert setTitle:@"Incorrect Password"];
        [alert setMessage:@""];
        [alert setDelegate:self];
        [alert addButtonWithTitle:@"Try Again"];
        [alert show];
    }
}
它在弹出视图控制器时工作,当它不在if语句中但由于某种奇怪的原因在使用上述代码时中断时也工作。警报视图工作正常!这只是推动!请帮忙

在App Delegate.h中:

    NavigationViewController *navView;
下面是应用程序委托(这将创建我创建的navigationController类的实例,该类基于通用类):

以下是日志:

2014-03-06 22:15:43.552 TopOPPS REP APP[795:70b] Application windows are expected to have a root view controller at the end of application launch 2014-03-06 22:16:18.728 TopOPPS REP APP[795:70b] -[LogInViewController textEnded:]: unrecognized selector sent to instance 0x109412a90 2014-03-06 22:16:18.730 TopOPPS REP APP[795:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LogInViewController textEnded:]: unrecognized selector sent to instance 0x109412a90' *** First throw call stack: ( 0 CoreFoundation 0x0000000101890795 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001015f3991 objc_exception_throw + 43 2 CoreFoundation 0x0000000101921bad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010188209d ___forwarding___ + 973 4 CoreFoundation 0x0000000101881c48 _CF_forwarding_prep_0 + 120 5 UIKit 0x00000001002570ae -[UIApplication sendAction:to:from:forEvent:] + 104 6 UIKit 0x0000000100257044 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17 7 UIKit 0x000000010032b450 -[UIControl _sendActionsForEvents:withEvent:] + 203 8 UIKit 0x000000010085a6d5 -[UITextField _resignFirstResponder] + 256 9 UIKit 0x000000010037ee40 -[UIResponder resignFirstResponder] + 222 10 UIKit 0x000000010085a4de -[UITextField resignFirstResponder] + 114 11 UIKit 0x000000010029b888 -[UIView setUserInteractionEnabled:] + 285 12 UIKit 0x000000010087f7b5 -[_UIViewControllerTransitionContext _disableInteractionForViews:] + 194 13 UIKit 0x0000000100364ce5 -[UINavigationController pushViewController:transition:forceImmediate:] + 1038 14 TopOPPS REP APP 0x000000010000254a -[LogInViewController logInHit:] + 202 15 UIKit 0x0000000100257096 -[UIApplication sendAction:to:from:forEvent:] + 80 16 UIKit 0x0000000100257044 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17 17 UIKit 0x000000010032b450 -[UIControl _sendActionsForEvents:withEvent:] + 203 18 UIKit 0x000000010032a9c0 -[UIControl touchesEnded:withEvent:] + 530 19 UIKit 0x000000010028bc15 -[UIWindow _sendTouchesForEvent:] + 701 20 UIKit 0x000000010028c633 -[UIWindow sendEvent:] + 988 21 UIKit 0x0000000100265fa2 -[UIApplication sendEvent:] + 211 22 UIKit 0x0000000100253d7f _UIApplicationHandleEventQueue + 9549 23 CoreFoundation 0x000000010181fec1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 24 CoreFoundation 0x000000010181f792 __CFRunLoopDoSources0 + 242 25 CoreFoundation 0x000000010183b61f __CFRunLoopRun + 767 26 CoreFoundation 0x000000010183af33 CFRunLoopRunSpecific + 467 27 GraphicsServices 0x00000001039983a0 GSEventRunModal + 161 28 UIKit 0x0000000100256043 UIApplicationMain + 1010 29 TopOPPS REP APP 0x0000000100001d53 main + 115 30 libdyld.dylib 0x0000000101f1f5fd start + 1 31 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException 2014-03-06 22:15:43.552 TopOPPS REP APP[795:70b]应用程序窗口预计在应用程序启动结束时会有一个根视图控制器 2014-03-06 22:16:18.728 TopOPPS代表应用程序[795:70b]-[LogInViewController textEnded:]:发送到实例0x109412a90的选择器无法识别 2014-03-06 22:16:18.730 TopOPPS代表应用程序[795:70b]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[LogInViewController textEnded::::]:未识别的选择器发送到实例0x109412a90' ***第一次抛出调用堆栈: ( 0 CoreFoundation 0x0000000101890795例外预处理+165 1 libobjc.A.dylib 0x00000001015f3991 objc_异常_抛出+43 2 CoreFoundation 0x0000000101921bad-[NSObject(NSObject)不识别选择器:][205 3 CoreFoundation 0x000000010188209d\uuuuuuuuuuuuuuuuu+973 4 CoreFoundation 0x0000000101881c48\u CF\u转发\u准备\u 0+120 5 UIKit 0x00000001002570ae-[UIApplication sendAction:to:from:forEvent:][104 6 UIKit 0x0000000100257044-[UIApplication sendAction:toTarget:fromSender:forEvent:+17 7 UIKit 0x000000010032b450-[UIControl\u发送操作预防:带事件:][203 8 UIKit 0x000000010085a6d5-[UITextField\u辞职第一响应者]+256 9 UIKit 0x000000010037ee40-[UIResponder Responder resignFirstResponder]+222 10 UIKit 0x000000010085a4de-[UITextField辞职第一响应者]+114 11 UIKit 0x000000010029b888-[UIView setUserInteractionEnabled:+285 12 UIKit 0x000000010087f7b5-[\u UIViewControllerTransitionContext\u disableInteractionForViews:][194 13 UIKit 0x0000000100364ce5-[UINavigationController推送视图控制器:转换:强制立即:+1038 14 TopOPPS代表应用程序0x000000010000254a-[LogInViewController登录信息:][202 15 UIKit 0x0000000100257096-[UIApplication sendAction:to:from:forEvent:][80 16 UIKit 0x0000000100257044-[UIApplication sendAction:toTarget:fromSender:forEvent:][17 17 UIKit 0x000000010032b450-[UIControl\u发送操作预防:带事件:][203 18 UIKit 0x000000010032a9c0-[UIControl触摸附加:withEvent:][530 19 UIKit 0x000000010028bc15-[UIWindow\u sendTouchesForEvent:+701 20 UIKit 0x000000010028c633-[UIWindow sendEvent:+988 21 UIKit 0x0000000100265fa2-[UIApplication sendEvent:+211 22 UIKit 0x0000000100253d7f_UIApplicationHandleEventQueue+9549 23 CoreFoundation 0x000000010181fec1\uuuu CFRUNLOOP\u正在调用\u OUT\u以执行\u函数\uuu+17 24 CoreFoundation 0x000000010181f792\uu CFRunLoopDoSources0+242 25 CoreFoundation 0x000000010183b61f__CFRunLoopRun+767 26 CoreFoundation 0x000000010183af33 CFRunLoopRunSpecific+467 27图形服务0x00000001039983a0 GSEventRunModal+161 28 UIKit 0x0000000100256043 UIApplicationMain+1010 29 TopOPPS代表应用程序0x0000000100001d53主+115 30 libdyld.dylib 0x0000000101f1f5fd启动+1 31°?0x0000000000000001 0x0+1 ) libc++abi.dylib:以NSException类型的未捕获异常终止
我检查了你的代码,工作完全正常。。。 但您必须在appDelegate方法中设置以下内容

 LogInViewController *loginVC = [[LogInViewController alloc] initWithNibName:@"LogInViewController" bundle:nil];

 UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginVC];

 self.window.rootViewController = navController;
根据你的控制台日志,我可以这么说

您以前创建了一个名为-(iAction)textEnd:(id)sender{}的方法,并将该方法链接到了按钮或文本化的任意位置,现在您删除了该方法,并且忘记了从file Inputer中删除该方法链接

只需从文件检查器中再次检查您的链接,确认所有方法是否可用


我在创建-(iAction)textEnd:(id)发送方{}时遇到了相同的错误方法并链接到UITextfield以编辑来自file Inputer的DidEnd操作,然后我从.m文件中删除了整个方法,并且在单击登录按钮时出现了相同的错误,因此请检查您的所有链接是否都有可用的链接方法。首先,您必须在appDelegate中设置根视图控制器,如

 LogInViewController *loginVC = [[LogInViewController alloc] initWithNibName:@"LogInViewController" bundle:nil];
 UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginVC];
 self.window.rootViewController = navController;
我想你不熟悉if的情况

你应该这样写

- (IBAction)logInHit:(id)sender {

    if (passWord ) {
        DashBoardViewController *dash = [[DashBoardViewController alloc] initWithNibName:@"DashBoardViewController" bundle:nil];
        [self.navigationController pushViewController:dash animated:YES];
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] init];
        [alert setTitle:@"Incorrect Password"];
        [alert setMessage:@""];
        [alert setDelegate:self];
        [alert addButtonWithTitle:@"Try Again"];
        [alert show];
    }
}
好的,我明白了

在“LogInViewController”的NIB文件中,您创建了一个名为“textEnded”的操作,然后删除了该方法,但没有删除NIB中的引用

要解决此问题,请转到LogInViewController NIB以查看界面生成器,单击UITextFields,并在Connections Inspector中查找Sent Events类别上的方法“textEnded”。之后,单击“X”图标以删除引用

请参见此图作为参考:


您使用的是xib还是故事板请指导我。你能调试一下你的公司吗
- (IBAction)logInHit:(id)sender {

    if (passWord ) {
        DashBoardViewController *dash = [[DashBoardViewController alloc] initWithNibName:@"DashBoardViewController" bundle:nil];
        [self.navigationController pushViewController:dash animated:YES];
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] init];
        [alert setTitle:@"Incorrect Password"];
        [alert setMessage:@""];
        [alert setDelegate:self];
        [alert addButtonWithTitle:@"Try Again"];
        [alert show];
    }
}