-1

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
Baby
  • 5,062
  • 3
  • 30
  • 52
DSki867
  • 19
  • 4
  • are you using xib or storyboard – Muralikrishna Mar 07 '14 at 04:02
  • Please guide me. can you please debug your code and let us know? on which place your code break. –  Mar 07 '14 at 04:03
  • Do you want me to paste the debug console? – DSki867 Mar 07 '14 at 04:07
  • are you using Xib if not DashBoardViewController *dash = [[DashBoardViewController alloc] init]; [self.navigationController pushViewController:dash animated:YES]; – Charan Giri Mar 07 '14 at 04:09
  • I am using a xib for the dash view – DSki867 Mar 07 '14 at 04:11
  • And I am just trying to create a login screen so when I click "login", it checks to see what the text equals in the password text field and then either alertviews or pushes a new controller and the push part is what isn't working – DSki867 Mar 07 '14 at 04:12
  • I am using all xib files, no storyboard – DSki867 Mar 07 '14 at 04:13
  • is the if condition true ? try checking with breakpoints. – GoGreen Mar 07 '14 at 04:13
  • And yes, in the app delegate I make a navController. – DSki867 Mar 07 '14 at 04:13
  • With the navController I make a rootviewcontroller and that is the login screen. This code is in that view controller to move you to the next one. – DSki867 Mar 07 '14 at 04:14
  • The if condition is true, I checked it with a print out in the console – DSki867 Mar 07 '14 at 04:15
  • could you paste the console log ? – GoGreen Mar 07 '14 at 04:15
  • I checked with breakpoints and the code gets to the push call line and breaks their so it is breaking on the push. – DSki867 Mar 07 '14 at 04:17
  • ok.. I get the idea..it would be helpful if you add the console log – GoGreen Mar 07 '14 at 04:18
  • I just added the console log. Thanks for the help! – DSki867 Mar 07 '14 at 04:19
  • The root view controller is not setting properly it seems. Could you paste the code on how you set the root ViewController – GoGreen Mar 07 '14 at 04:26
  • I just posted the rootview code – DSki867 Mar 07 '14 at 04:30
  • 3
    Okey, you're not setting the rootviewcontroller of the window properly. You should have this: self.window.rootViewController = navView; , and remove "[self.window addSubview:navView.view];" – Rodrigo Ayala Mar 07 '14 at 04:33
  • Unfortunately what Rodrigo said didn't fix it! – DSki867 Mar 07 '14 at 04:37
  • Please add proper explaination, so other user can help you, you are not providing any info about UItextfld related and crash log shows that. –  Mar 07 '14 at 05:12
  • you can check this in the UITextField delegate method `textFieldDidEndEditing`. Here is a link to a [stackoverflow answer](http://stackoverflow.com/questions/6997668/how-do-i-know-if-the-text-of-a-uitextfield-has-been-modified-by-user) – GoGreen Mar 07 '14 at 05:19
  • let me give you a heads up. in **stackoverflow** _"**never modify an existing question to ask another question !**"_. Its always advised to post it as a separate question. – GoGreen Mar 07 '14 at 05:21

3 Answers3

0

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

jayraj m.g.
  • 625
  • 5
  • 18
  • This didn't work for me. Is it that I didn't put it in the rightplace? – DSki867 Mar 07 '14 at 04:40
  • i make your - (IBAction)logInHit:(id)sender {} code at my page and check that code its working fine..... – jayraj m.g. Mar 07 '14 at 04:43
  • set my answered code in below method: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {......} – jayraj m.g. Mar 07 '14 at 04:43
  • can you tell me that did you calling your logInHit method programatically or using xib and linked that method to button? – jayraj m.g. Mar 07 '14 at 04:45
  • That still didn't work. My issue is that the login page loads fine but then when I type in a password and click login, it breaks – DSki867 Mar 07 '14 at 04:46
  • I linked the method to the button – DSki867 Mar 07 '14 at 04:46
  • do u have any textEnd: method in loginviewcontroller? – jayraj m.g. Mar 07 '14 at 04:48
  • - (IBAction)textChanged:(id)sender { if ([_passwordField.text isEqualToString:@"password"]) passWord = true; else passWord = false; } – DSki867 Mar 07 '14 at 04:48
  • I have that which is a textChanged method but I don't have an ending method. How do you write one of those? – DSki867 Mar 07 '14 at 04:49
  • Actually that method shouldn't even matter because it passes the check to see if the password is right. I checked breakpoints and it goes into the if statement but then breaks only when it wants to push the new view controller – DSki867 Mar 07 '14 at 04:54
  • your console log is saying that [LogInViewController textEnded:]: unrecognized selector sent to instance 0x109412a90' so i think that you have to double check your links in file inspector and program that all methods are availble and you did not call any method which is not exist... – jayraj m.g. Mar 07 '14 at 05:02
  • What @jayrajm.g. said should work. you have to write the code mentioned in this answer in the `applicationDidFinishLaunchingWithOptions` method in the appDelegate file. – GoGreen Mar 07 '14 at 05:02
  • what is linked to the IBAction `textChanged` method in the xib? – GoGreen Mar 07 '14 at 05:05
  • So I did all that but it's still breaking when it tries to push that second View Controller on there. I check to see if text Value changes and if it does then I change a bool and that is all working because it wouldn't get into the if statement otherwise but then right when it pushes it breaks – DSki867 Mar 07 '14 at 05:05
  • I think the problem is in the xib file. You might have linked two IBAction methods to the textField to check for the text change. Please do Check if there is an extra method called `textEnd:` by right-clicking on your textField, and if so remove it. – GoGreen Mar 07 '14 at 05:08
  • The text field seems to be the issue. I made a valueChanged method based off of a UITextField in the xib – DSki867 Mar 07 '14 at 05:09
  • just keep the link to the method you are using now and remove any previous links to other methods that you have deleted. – GoGreen Mar 07 '14 at 05:12
  • 1
    @DSki867: Please add proper explaination, so other user can help you, you are not providing any info about UItextfld related and crash log shows that. –  Mar 07 '14 at 05:13
  • That was it! that was the issue! I had too many connections. Now my issue is which method to use? Editing did end? How do I get the text field to check to see if it has the right answer and then change a boolean? – DSki867 Mar 07 '14 at 05:14
  • @DSki867: use Editing Changed method for checking password and remember to remove other links otherwise get same error again and check my edited answer.. – jayraj m.g. Mar 07 '14 at 05:16
  • you can check this in the UITextField delegate method `textFieldDidEndEditing`. Here is a link to a [stackoverflow answer](http://stackoverflow.com/questions/6997668/how-do-i-know-if-the-text-of-a-uitextfield-has-been-modified-by-user) – GoGreen Mar 07 '14 at 05:17
0

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

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

Rodrigo Ayala
  • 500
  • 5
  • 7