gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:12:31 26 4
gpt4 key购买 nike

每次按下登录按钮时都会出现此错误我尝试了各种方法但不知道如何解决代码是这样的

#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 选项卡下的 Interface builder 中,确保 .nib 文件的父级是 ViewController
  • 在同一个 Identity & Type 选项卡下,确保没有任何旧的未使用的 IBOutlet 按钮卡在旁边并带有警告标志
  • 右键单击界面生成器中的 View 按钮并检查 _login 附加到 IB 中的按钮的引用 socket
  • SHIFT + K + Apple Cmd清理并再次尝试构建

关于ios - 无法识别的选择器发送到实例 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22081871/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com