无法识别的选择器发送到控制器实例

时间:2014-02-02 15:23:44

标签: ios objective-c memory-management unrecognized-selector

我对Xcode中的Objective C编程很新,遇到了我想要的应用程序的问题。我在某处读到这是关于释放内存的,但由于我是新手,我不知道如何解决这个问题。

这是我的代码似乎包含问题。

#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

我点击了名为signUp的操作按钮,我收到此错误:

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

3 个答案:

答案 0 :(得分:1)

在错误日志中,您会看到您在控制器上调用signIn:的原因 -[SignUpViewController signIn:]

然而,您的控制器类不实现signIn:而是signUp:。所以相应地替换你的方法调用。

答案 1 :(得分:1)

我找到了答案,非常简单。我将signUp按钮连接到故事板中连接检查器中的两个方法,我需要做的就是删除一个。谢谢你的帮助。

答案 2 :(得分:0)

在您的代码中,您没有名为signIn的方法?有signUp但没有signIn据我所知,也没有调用该方法。您确定发布了整个代码吗?无论如何添加它,它会工作。

- (IBAction)signIn:(id)sender 
{
    NSLog(@"Sign In man ...");
}