Question

I have already created a navigation controller in another class with a root view controller(the login screen). When I hit the login button I want it to push to the dashboard view controller. Here is my code

- (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];
    }
}

It works when it pops a view controller and it also works when it is not in the if statement but for some odd reason it breaks when using the code above. The alert view works fine! It is just the push! Please help!

In the App Delegate.h:

    NavigationViewController *navView;

Here is the App Delegate (This creates an instance of the navigationController class that I made which is based off of the generic one):

    LogInViewController *logInView = [[LogInViewController alloc] init];
navView = [[NavigationViewController alloc] initWithRootViewController:logInView];


[self.window addSubview:navView.view];

Here is the Log:

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
Was it helpful?

Solution

Ok I got it!

In the NIB file of "LogInViewController", you created an Action called "textEnded", and after that you removed that method, but not the reference from the NIB.

To fix this, go to the LogInViewController NIB to see the Interface Builder, click on your UITextFields, and look inside the Connections Inspector for the method "textEnded" on the Sent Events category. After that, click on the "X" icon to remove the reference.

See this image as a reference:

enter image description here

OTHER TIPS

1st You have to set root view Controller in appDelegate like,

 LogInViewController *loginVC = [[LogInViewController alloc] initWithNibName:@"LogInViewController" bundle:nil];
 UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:loginVC];
 self.window.rootViewController = navController;

I think you are not familiar with if condition.

You should write like this

- (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];
    }
}

i checked your code its working complete fine... but you have to set below in your appDelegate method

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

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

 self.window.rootViewController = navController;

as per your Console Log i can say that

you created one method called -(IBAction)textEnd:(id)sender{} before and linked that method to anywhere to button or textfied and now you removed that method and you forget to remove that method link from file inpector...

just double check your link from file inspector that all methods are available or not...

i got same error when i create -(IBAction)textEnd:(id)sender{} method and linked to UITextfield to EditingDidEnd action from file inpector and than i remove method whole method from my .m file and i got same error on click of login button so check your all links are have availabled linked methods

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top