繁体   English   中英

无法识别的选择器已发送到实例ios

[英]unrecognized selector sent to instance ios

每次按下按钮登录时,都会遇到各种错误,但我不知道该如何解决。

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UITextField *user;

@property (weak, nonatomic) IBOutlet UITextField *password;

@property (weak, nonatomic) IBOutlet UIButton *login;

@end



@implementation ViewController


- (void)viewDidLoad
{

    [super viewDidLoad];

     [_login addTarget:self action:@selector(loginControllo) forControlEvents:UIControlEventTouchUpInside];


}



- (void)loginControllo
{



    NSString *rawStr = [NSString stringWithFormat:@"username=%@&password=%@", [_user text],
                        [_password text]];

    NSData *data = [rawStr dataUsingEncoding:NSUTF8StringEncoding];

    NSURL *url = [NSURL URLWithString:@"http://www.example.com/app/b/login.php"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:data];
    NSURLResponse *response;
    NSError *err;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];

    NSString *responseString = [NSString stringWithUTF8String:[responseData bytes]];
    NSLog(@"%@", responseString);


    if ([responseString  isEqualToString: @"0"]) {
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"Errore"
                              message:@"Errore nel Login"
                              delegate:nil //or self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];

        [alert show];

    }else{
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"Ok"
                              message:@"Login Ok"
                              delegate:nil //or self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];

        [alert show];
    }


    [self dismissViewControllerAnimated:YES completion:nil];



 }


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

按下登录按钮后返回此错误

2014-02-27 23:01:15.430 Prima[729:70b] -[ViewController login:]: unrecognized    selector sent to instance 0x8b93e30
2014-02-27 23:01:15.433 Prima[729:70b] *** Terminating app due to uncaught exception    'NSInvalidArgumentException', reason: '-[ViewController login:]: unrecognized selector   sent to instance 0x8b93e30'
*** First throw call stack:
(
0   CoreFoundation                      0x0173b5e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x014be8b6 objc_exception_throw + 44
2   CoreFoundation                      0x017d8903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3   CoreFoundation                      0x0172b90b ___forwarding___ + 1019
4   CoreFoundation                      0x0172b4ee _CF_forwarding_prep_0 + 14
5   libobjc.A.dylib                     0x014d0874 -[NSObject performSelector:withObject:withObject:] + 77
6   UIKit                               0x0022e0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
7   UIKit                               0x0022e04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8   UIKit                               0x003260c1 -[UIControl sendAction:to:forEvent:] + 66
9   UIKit                               0x00326484 -[UIControl _sendActionsForEvents:withEvent:] + 577
10  UIKit                               0x00325733 -[UIControl touchesEnded:withEvent:] + 641
11  UIKit                               0x0026b51d -[UIWindow _sendTouchesForEvent:] + 852
12  UIKit                               0x0026c184 -[UIWindow sendEvent:] + 1232
13  UIKit                               0x0023fe86 -[UIApplication sendEvent:] + 242
14  UIKit                               0x0022a18f _UIApplicationHandleEventQueue + 11421
15  CoreFoundation                      0x016c483f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16  CoreFoundation                      0x016c41cb __CFRunLoopDoSources0 + 235
17  CoreFoundation                      0x016e129e __CFRunLoopRun + 910
18  CoreFoundation                      0x016e0ac3 CFRunLoopRunSpecific + 467
19  CoreFoundation                      0x016e08db CFRunLoopRunInMode + 123
20  GraphicsServices                    0x036e09e2 GSEventRunModal + 192
21  GraphicsServices                    0x036e0809 GSEventRun + 104
22  UIKit                               0x0022cd3b UIApplicationMain + 1225
23  Prima                               0x000033bd main + 141
24  libdyld.dylib                       0x01d7970d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

无法解决此问题可能是由什么引起的? 非常感谢您的关注

我想到了几件事

  • 在“接口”构建器中,IB旁边的“ Identity & Type选项卡下,确保.nib文件的父级是ViewController类。
  • 在同一“ Identity & Type选项卡下,确保没有任何旧的未使用的IBOutlet按钮在旁边悬挂并带有警告标志
  • 右键单击“界面”构建器中的“查看”按钮,然后检查_login附加到IB中的按钮的引用出口。
  • SHIFT + K + Apple Cmd清理并尝试再次构建

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM