2014-02-27 67 views
0

我得到這個錯誤每次我按下按鈕登錄 我在各方面嘗試,但不知道如何解決 的代碼是這個發送到實例無法識別選擇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) 

不能解決這個問題可以引起什麼? 非常感謝你的關注

+0

建設請問您的.xib按鈕連接到一個方法也? – WDUK

+0

這是我沒有做任何事的代碼.. –

+1

你提供的代碼看起來應該可以工作。我問的原因是因爲崩潰表明它正在尋找'login:'方法,而事實上它應該尋找'loginControllo'。如果你檢查你的界面生成器文件,看看它是否連接到任何IBActions。 – WDUK

回答

1

有幾件事情想到

  • 在Interface Builder Identity & Type標籤旁邊IB下,確保你的筆尖文件的父是ViewController
  • 在相同的Identity & Type選項卡下,確保沒有任何舊的未使用的IBOutlet按鈕正在環繞並在其旁邊有警告標誌
  • 右鍵單擊「界面」構建器中的查看按鈕,然後檢查參考插座_login連接到一個按鈕IB
  • SHIFT + K + Apple Cmd清洗,然後再試一次
相關問題