-2

I am fairly new to programming Objective C in Xcode and ran into a problem with an app I am trying to make. I read somewhere that this is about memory releasing but since I am new I am not sure quite how to fix this.

Here is my code which seems to contain the problem.

#import "SignUpViewController.h"
@interface SignUpViewController () <UITextFieldDelegate> 
@end

@implementation SignUpViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.fullName.delegate = self;
    self.usernameField.delegate = self;
    self.passwordField.delegate = self;
    self.emailField.delegate = self;

    self.navigationItem.title = @"SIGN UP";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.view.backgroundColor = [UIColor clearColor];

}

- (void)viewWillAppear:(BOOL)animated {


}



#pragma mark - Animations

-(void)textFieldDidBeginEditing:(UITextField *)textField {
    self.navigationController.navigationBar.hidden = YES;

    [UIView beginAnimations:nil context:NULL];

    CGRect fullName = CGRectMake(31, 51, 259, 30);
    CGRect usernameField = CGRectMake(31, 79, 259, 30);
    CGRect passwordField = CGRectMake(31, 107, 259, 30);
    CGRect emailField = CGRectMake(31, 135, 259, 30);
    CGRect signUpBox = CGRectMake(0, -360, 320, 610);
    CGRect signUpButton = CGRectMake(31, 183, 259, 30);

    [self.fullName setFrame:fullName];
    [self.usernameField setFrame:usernameField];
    [self.passwordField setFrame:passwordField];
    [self.emailField setFrame:emailField];
    [self.signUpBox setFrame:signUpBox];
    [self.signUpButton setFrame:signUpButton];

    [UIView commitAnimations];
}

-(void)textFieldDidEndEditing:(UITextField *)textField {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.7];

    CGRect fullName = CGRectMake(31, 369, 259, 30);
    CGRect usernameField = CGRectMake(31, 397, 259, 30);
    CGRect passwordField = CGRectMake(31, 425, 259, 30);
    CGRect emailField = CGRectMake(31, 453, 259, 30);
    CGRect signUpBox = CGRectMake(0, -42, 320, 610);
    CGRect signUpButton = CGRectMake(31, 501, 259, 30);

    [self.fullName setFrame:fullName];
    [self.usernameField setFrame:usernameField];
    [self.passwordField setFrame:passwordField];
    [self.emailField setFrame:emailField];
    [self.signUpBox setFrame:signUpBox];
    [self.signUpButton setFrame:signUpButton];

    [UIView commitAnimations];
    self.navigationController.navigationBar.hidden = NO;
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

#pragma mark - Helper Methods

- (IBAction)signUp:(id)sender {
    NSString *fullName = self.fullName.text;
    NSString *username = self.usernameField.text;
    NSString *password = self.passwordField.text;
    NSString *email = self.emailField.text;

    if ([username length] == 0 || [password length] == 0 || [email length] == 0 || [fullName length] == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Make sure you enter a username, password and email." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }
}
@end

I click on the button with action called signUp and I get this error:

2014-02-02 15:22:42.909 PhotosApp2[1538:80b] -[SignUpViewController signIn:]: unrecognized selector sent to instance 0x10e754210
2014-02-02 15:22:42.913 PhotosApp2[1538:80b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SignUpViewController signIn:]: unrecognized selector sent to instance 0x10e754210'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000102741795 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001024a4991 objc_exception_throw + 43
    2   CoreFoundation                      0x00000001027d2bad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010273309d ___forwarding___ + 973
    4   CoreFoundation                      0x0000000102732c48 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x0000000101108096 -[UIApplication sendAction:to:from:forEvent:] + 80
    6   UIKit                               0x0000000101108044 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
    7   UIKit                               0x00000001011dc450 -[UIControl _sendActionsForEvents:withEvent:] + 203
    8   UIKit                               0x00000001011db9c0 -[UIControl touchesEnded:withEvent:] + 530
    9   UIKit                               0x000000010113cc15 -[UIWindow _sendTouchesForEvent:] + 701
    10  UIKit                               0x000000010113d633 -[UIWindow sendEvent:] + 988
    11  UIKit                               0x0000000101116fa2 -[UIApplication sendEvent:] + 211
    12  UIKit                               0x0000000101104d7f _UIApplicationHandleEventQueue + 9549
    13  CoreFoundation                      0x00000001026d0ec1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    14  CoreFoundation                      0x00000001026d0792 __CFRunLoopDoSources0 + 242
    15  CoreFoundation                      0x00000001026ec61f __CFRunLoopRun + 767
    16  CoreFoundation                      0x00000001026ebf33 CFRunLoopRunSpecific + 467
    17  GraphicsServices                    0x00000001038703a0 GSEventRunModal + 161
    18  UIKit                               0x0000000101107043 UIApplicationMain + 1010
    19  PhotosApp2                          0x0000000100004a53 main + 115
    20  libdyld.dylib                       0x000000010300f60d start + 1
    21  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
rmaddy
  • 314,917
  • 42
  • 532
  • 579
jacobsieradzki
  • 1,108
  • 2
  • 10
  • 32
  • Was your action method `-signUp:` once called `'-signIn:`? If so, your XIB may not have been updated for the new method name. – Extra Savoir-Faire Feb 02 '14 at 15:28
  • You have `singUp:` method there not `signIn:` so maybe some wrong button target method configuration? And use rather `[UIView animateWith...]` methods than `beginAnimations`. – Maciej Oczko Feb 02 '14 at 15:28
  • 1
    In which line you are getting this error?? – Hussain Shabbir Feb 02 '14 at 15:38
  • 4
    Fer cryin' out loud, did you Google "unrecognized selector" before posting your question? You'd have gotten thousands of hits. – Hot Licks Feb 02 '14 at 15:39
  • possible duplicate of [\[UITapGestureRecognizer tag\]: unrecognized selector sent to instance](http://stackoverflow.com/questions/19152573/uitapgesturerecognizer-tag-unrecognized-selector-sent-to-instance) – Yunus Nedim Mehel Feb 02 '14 at 16:04
  • I looked through the internet and none of what appears seems to apply to my problem. There is no reference in either of the header or implementation files of SignUpViewController to a `signIn` method or anything else. I searched the whole code with Command F to be sure. – jacobsieradzki Feb 02 '14 at 17:54
  • I also tried changing the signUp method to signIn to see if anything changed but I had the same error except with `[SignUpViewController signUp:]` this time – jacobsieradzki Feb 02 '14 at 17:55
  • Uh, SignUpViewController is *your* class -- obviously you're not going to find it via Google (except someone else's entirely different version). And if nothing else, *READ THE MESSAGE!!* it says you're trying to invoke a method named "signIn:". – Hot Licks Feb 02 '14 at 22:28
  • I understand that SignUpViewController is my class, I'm not so new that I don't realise that, I searched unrecognized selector problem. And to be honest, you can't exactly get frustrated because I did find the answer which no one suggested here and nor did I find it on the internet. – jacobsieradzki Feb 03 '14 at 14:07

3 Answers3

1

In your error log you see the reason is you are calling signIn: on your controller -[SignUpViewController signIn:]

Yet, you controller class does not implement signIn:but signUp:. So replace your method call accordingly.

Volker
  • 4,640
  • 1
  • 23
  • 31
  • I looked through my whole header and implementation file and there are no signIn methods or references to anything called signIn since I searched the code using Command-F. I tried changing the method name to signUp in both files to see if that worked but then the console said the same error but saying: [SignUpViewController signUp:] ... the reverse of what I had before! I have looked on the internet for an answer but I don't think any of them really apply to me. – jacobsieradzki Feb 02 '14 at 17:50
  • somewhere in code or xib the method is called and leads to the crash. – Volker Feb 02 '14 at 22:00
1

I found the answer, quite simple really. I had the signUp button connected to two methods in connections inspector in the storyboard and all I needed to do was to delete one. Thanks for the help.

jacobsieradzki
  • 1,108
  • 2
  • 10
  • 32
0

In your code you have no method called signIn? There is signUp but no signIn As far as I can see there is no call to that method either. Are you sure you posted your whole code. Anyways add this and it will work.

- (IBAction)signIn:(id)sender 
{
    NSLog(@"Sign In man ...");
}
Sam B
  • 27,273
  • 15
  • 84
  • 121