gpt4 book ai didi

cocoa - 使用 :(id) sender on an IBAction 时,应用程序由于未捕获的异常而终止

转载 作者:行者123 更新时间:2023-12-03 18:02:11 25 4
gpt4 key购买 nike

我有一个使用模态视图的应用程序,上面有一些按钮。当我按下按钮时,我将调用以下函数:

-(IBAction)iconWasSelected:(id) sender
{
NSLog(@"icon button was pressed");
[self dismissModalViewControllerAnimated:YES];
}

如果我删除 :(id) 发件人;它工作得很好,但我试图获取触发该函数的对象。

这是“呕吐”的错误:

2011-03-11 22:59:55.793 app[14107:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[IconPickerViewController iconWasSelected]: unrecognized selector sent to instance 0x800bbf0'
*** Call stack at first throw:
(
0 CoreFoundation 0x01629be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0177e5c2 objc_exception_throw + 47
2 CoreFoundation 0x0162b6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0159b366 ___forwarding___ + 966
4 CoreFoundation 0x0159af22 _CF_forwarding_prep_0 + 50
5 UIKit 0x0053da6e -[UIApplication sendAction:to:from:forEvent:] + 119
6 UIKit 0x005cc1b5 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x005ce647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
8 UIKit 0x005cd1f4 -[UIControl touchesEnded:withEvent:] + 458
9 UIKit 0x005620d1 -[UIWindow _sendTouchesForEvent:] + 567
10 UIKit 0x0054337a -[UIApplication sendEvent:] + 447
11 UIKit 0x00548732 _UIApplicationHandleEvent + 7576
12 GraphicsServices 0x01ce4a36 PurpleEventCallback + 1550
13 CoreFoundation 0x0160b064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
14 CoreFoundation 0x0156b6f7 __CFRunLoopDoSource1 + 215
15 CoreFoundation 0x01568983 __CFRunLoopRun + 979
16 CoreFoundation 0x01568240 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x01568161 CFRunLoopRunInMode + 97
18 GraphicsServices 0x01ce3268 GSEventRunModal + 217
19 GraphicsServices 0x01ce332d GSEventRun + 115
20 UIKit 0x0054c42e UIApplicationMain + 1160
21 naggy 0x00002298 main + 102
22 naggy 0x00002229 start + 53
)
terminate called after throwing an instance of 'NSException'

有什么线索吗?!!帮助和感谢!!

最佳答案

如果您以编程方式调用该方法,请确保正确设置操作。例如,当 (id)sender 存在时,这将起作用:

UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle:@"CLICK ME" 
style:UIBarButtonItemStyleBordered
target:self
action:@selector(iconWasSelected:)];

(id)sender 不存在时,这将起作用:

UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle:@"CLICK ME" 
style:UIBarButtonItemStyleBordered
target:self
action:@selector(iconWasSelected)];

请注意,代码中唯一的区别是冒号!

关于cocoa - 使用 :(id) sender on an IBAction 时,应用程序由于未捕获的异常而终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5280494/

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