gpt4 book ai didi

ios - 未声明的选择器 goBack 警告和无法识别的选择器发送到实例终止

转载 作者:行者123 更新时间:2023-12-01 17:54:24 24 4
gpt4 key购买 nike

我一直在阅读许多类似的问题和答案,但仍然不太明白这里出了什么问题。

我正在尝试创建一个按钮以返回上一个 View ,但我不断收到标题中提到的错误。有人可以告诉我我做错了什么吗?

 UIImage *image = [UIImage imageNamed:@"listbutton.png"];
UIButton *listbutton = [UIButton buttonWithType:UIButtonTypeCustom];
listbutton.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );
[listbutton setImage:image forState:UIControlStateNormal];
[listbutton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:listbutton];

回去:
- (void)goBack
{
[self.navigationController popViewControllerAnimated:YES];
}

错误:

2014-01-05 22:03:13.344 tablepractice[12509:70b] -[DetailViewController goBack:]: unrecognized selector sent to instance 0x8b72130 2014-01-05 22:03:13.348 tablepractice[12509:70b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailViewController goBack:]: unrecognized selector sent to instance 0x8b72130' * First throw call stack: ( 0 CoreFoundation 0x017405e4 exceptionPreprocess + 180 1 libobjc.A.dylib
0x014c38b6 objc_exception_throw + 44 2 CoreFoundation
0x017dd903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275 3
CoreFoundation 0x0173090b __forwarding
+ 1019 4 CoreFoundation 0x017304ee _CF_forwarding_prep_0 + 14 5 libobjc.A.dylib 0x014d5874 -[NSObject performSelector:withObject:withObject:] + 77 6 UIKit 0x002330c2 -[UIApplication sendAction:to:from:forEvent:] + 108 7 UIKit
0x0023304e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61 8 UIKit 0x0032b0c1 -[UIControl sendAction:to:forEvent:] + 66 9 UIKit
0x0032b484 -[UIControl _sendActionsForEvents:withEvent:] + 577 10 UIKit 0x0032a733 -[UIControl touchesEnded:withEvent:] + 641 11 UIKit
0x0027051d -[UIWindow _sendTouchesForEvent:] + 852 12 UIKit
0x00271184 -[UIWindow sendEvent:] + 1232 13 UIKit
0x00244e86 -[UIApplication sendEvent:] + 242 14 UIKit
0x0022f18f _UIApplicationHandleEventQueue + 11421 15 CoreFoundation 0x016c983f CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15 16 CoreFoundation 0x016c91cb __CFRunLoopDoSources0 + 235 17 CoreFoundation 0x016e629e __CFRunLoopRun + 910 18 CoreFoundation
0x016e5ac3 CFRunLoopRunSpecific + 467 19 CoreFoundation
0x016e58db CFRunLoopRunInMode + 123 20 GraphicsServices
0x036e59e2 GSEventRunModal + 192 21 GraphicsServices
0x036e5809 GSEventRun + 104 22 UIKit
0x00231d3b UIApplicationMain + 1225 23 tablepractice
0x0000388d main + 141 24 libdyld.dylib
0x01d7e70d start + 1 25 ???
0x00000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

最佳答案

[listbutton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];

这需要更改为在选择器方法中不使用冒号:
[listbutton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];

冒号表示有参数,而您的 goBack 方法没有参数。

关于ios - 未声明的选择器 goBack 警告和无法识别的选择器发送到实例终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20942747/

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