[英]iOS, unrecognized selector sent to instance?
I got a mainscreen with a imported custom actionBar. 我有一个带有导入自定义actionBar的主屏幕。 I created this actionBar in a separate .xib file, with a .m and .h file.
我在一个单独的.xib文件中创建了这个actionBar,其中包含.m和.h文件。
I do some graphic setup in my actionBar.m's viewDidLoad
like backgroundColor
and some other stuff. 我在actionBar.m的
viewDidLoad
做了一些图形设置,比如backgroundColor
和其他一些东西。
I also got a button on this actionBar
i linked the way i usually link buttons, with a IBAction
. 我在这个
actionBar
上也有一个按钮,我通常用IBAction
链接按钮的方式。
I load my actionBar into my mainscreen like this: 我将actionBar加载到我的主屏幕中,如下所示:
ActionBarWithLogoff *actionBar = [[ActionBarWithLogoff alloc] initWithNibName:@"ActionBarWithLogoff" bundle:nil];
[topBar addSubview:actionBar.view];
[actionBar release];
My actionBar.h: 我的actionBar.h:
- (IBAction)ActionBarLogoff:(id)sender;
My actionBars.m's method: 我的actionBars.m的方法:
-(void) ActionBarLogoff:(UIButton *)sender
{
NSLog(@"!!!!!!!!!!ActionBarLogoff");
}
This is were my error steels the picture, when i click the button i get the following error: 这是我的错误钢铁图片,当我点击按钮我得到以下错误:
2014-01-27 13:52:21.856 GB_Mobil_DK[2954:60b] -[__NSArrayM ActionBarLogoff:]: unrecognized selector sent to instance 0x1656d880 2014-01-27 13:52:21.858 GB_Mobil_DK[2954:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM ActionBarLogoff:]: unrecognized selector sent to instance 0x1656d880' * First throw call stack: (0x2f94be83 0x39ca86c7 0x2f94f7b7 0x2f94e0af 0x2f89cdc8 0x32104da3 0x32104d3f 0x32104d13 0x320f0743 0x3210475b 0x32104425 0x320ff451 0x320d4d79 0x320d3569 0x2f916f1f 0x2f9163e7 0x2f914bd7 0x2f87f471 0x2f87f253 0x345b92eb 0x32134845 0x97985 0x3a1a1ab7) libc++abi.dylib: terminating with uncaught exception of type NSException
2014-01-27 13:52:21.856 GB_Mobil_DK [2954:60b] - [__ NSArrayM ActionBarLogoff:]:无法识别的选择器发送到实例0x1656d880 2014-01-27 13:52:21.858 GB_Mobil_DK [2954:60b] *终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因是: ' - [__ NSArrayM ActionBarLogoff:]:无法识别的选择发送到实例0x1656d880' *第一掷调用堆栈:(0x2f94be83 0x39ca86c7 0x2f94f7b7 0x2f94e0af 0x2f89cdc8 0x32104da3 0x32104d3f 0x32104d13 0x320f0743 0x3210475b 0x32104425 0x320ff451 0x320d4d79 0x320d3569 0x2f916f1f 0x2f9163e7 0x2f914bd7 0x2f87f471 0x2f87f253 0x345b92eb 0x32134845 0x97985 0x3a1a1ab7)libc ++ abi.dylib:以NSException类型的未捕获异常终止
Anyone able to tell me why? 有谁能告诉我为什么? and most importantly able to help me solve this problem^^?
最重要的是能够帮我解决这个问题^^?
You are releasing the actionBar
instance and just retaining its view
. 您正在释放
actionBar
实例并保留其view
。 If actionBar
instance is responder to button action, then button click message is getting sent to deleted instance. 如果
actionBar
实例响应按钮操作,则按钮单击消息将被发送到已删除的实例。 You should retain the actionBar
instance. 您应该保留
actionBar
实例。 One way to do this is making it an ivar or a retain
property. 一种方法是将其作为ivar或
retain
财产。
Also looks like you are creating a UIViewController
for a custom view. 看起来您正在为自定义视图创建
UIViewController
。 Instead you can create just a custom UIView
with its XIB. 相反,您可以使用其XIB创建自定义
UIView
。
EDIT 编辑
Declare retain property, 声明保留财产,
@property (nonatomic, retain) ActionBarWithLogoff *actionBar;
OR 要么
Simply declare as ivar, 简单地声明为ivar,
@interface YourViewController: UIViewController {
ActionBarWithLogoff *actionBar;
}
And in dealloc
method, 在
dealloc
方法中,
-(void) dealloc {
//...
[actionBar release];
//...
}
Hope that helps! 希望有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.