iOS,无法识别的选择器已发送到实例? [英] iOS, unrecognized selector sent to instance?

查看:60
本文介绍了iOS,无法识别的选择器已发送到实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有导入的自定义actionBar的主屏幕.我在一个单独的.xib文件(带有.m和.h文件)中创建了该actionBar.

I got a mainscreen with a imported custom actionBar. I created this actionBar in a separate .xib file, with a .m and .h file.

我在actionBar.m的 viewDidLoad 中进行了一些图形设置,例如 backgroundColor 等.

I do some graphic setup in my actionBar.m's viewDidLoad like backgroundColor and some other stuff.

我在这个 actionBar 上也有一个按钮,我将我通常链接按钮的方式与 IBAction 链接起来.

I also got a button on this actionBar i linked the way i usually link buttons, with a IBAction.

我将actionBar加载到主屏幕中,如下所示:

I load my actionBar into my mainscreen like this:

ActionBarWithLogoff *actionBar = [[ActionBarWithLogoff alloc] initWithNibName:@"ActionBarWithLogoff" bundle:nil];
[topBar addSubview:actionBar.view];
[actionBar release];

我的actionBar.h:

My actionBar.h:

- (IBAction)ActionBarLogoff:(id)sender;

我的actionBars.m的方法:

My actionBars.m's method:

-(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]-[__ NSArrayMActionBarLogoff:]:无法识别的选择器已发送到实例0x1656d8802014-01-27 13:52:21.858 GB_Mobil_DK [2954:60b] *正在终止应用程序未捕获异常"NSInvalidArgumentException",原因:'-[__ NSArrayM ActionBarLogoff:]:无法识别的选择器已发送至实例0x1656d880'* 第一个调用堆栈:(0x2f94be83 0x39ca86c7 0x2f94f7b7 0x2f94e0af 0x2f89cdc8 0x32104da3 0x32104d3f 0x32104d13 0x320f07430x3210475b 0x32104425 0x320ff451 0x320d4d79 0x320d3569 0x2f916f1f0x2f9163e7 0x2f914bd7 0x2f87f471 0x2f87f253 0x345b92eb 0x321348450x97985 0x3a1a1ab7)libc ++ abi.dylib:未捕获而终止NSException类型的异常

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

有人能告诉我为什么吗?最重要的是能够帮助我解决这个问题^^?

Anyone able to tell me why? and most importantly able to help me solve this problem^^?

推荐答案

您将释放 actionBar 实例,并仅保留其 view .如果 actionBar 实例是按钮动作的响应者,则按钮单击消息将发送到已删除的实例.您应该保留 actionBar 实例.一种方法是将其设置为ivar或 retain 属性.

You are releasing the actionBar instance and just retaining its view. If actionBar instance is responder to button action, then button click message is getting sent to deleted instance. You should retain the actionBar instance. One way to do this is making it an ivar or a retain property.

看起来您正在为自定义视图创建 UIViewController .相反,您只能使用其XIB创建自定义 UIView .

Also looks like you are creating a UIViewController for a custom view. Instead you can create just a custom UIView with its XIB.

编辑

声明保留属性,

@property (nonatomic, retain) ActionBarWithLogoff *actionBar;

OR

简单地声明为ivar,

Simply declare as ivar,

@interface YourViewController: UIViewController {
    ActionBarWithLogoff *actionBar;
}

dealloc 方法中,

-(void) dealloc {
    //...

    [actionBar release];

    //...
}

希望有帮助!

这篇关于iOS,无法识别的选择器已发送到实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆