簡體   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