iOS,无法识别的选择器发送到实例?

use*_*952 6 iphone xib ibaction ios

我有一个带有导入自定义actionBar的主屏幕.我在一个单独的.xib文件中创建了这个actionBar,其中包含.m和.h文件.

我做了一些图形设置在我actionBar.m的viewDidLoad喜欢backgroundColor和一些其他的东西.

我也有一个按钮,actionBar我通常链接按钮的方式链接,用IBAction.

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

ActionBarWithLogoff *actionBar = [[ActionBarWithLogoff alloc] initWithNibName:@"ActionBarWithLogoff" bundle:nil];
[topBar addSubview:actionBar.view];
[actionBar release];
Run Code Online (Sandbox Code Playgroud)

我的actionBar.h:

- (IBAction)ActionBarLogoff:(id)sender;
Run Code Online (Sandbox Code Playgroud)

我的actionBars.m的方法:

-(void) ActionBarLogoff:(UIButton *)sender
{
NSLog(@"!!!!!!!!!!ActionBarLogoff");
}
Run Code Online (Sandbox Code Playgroud)

这是我的错误钢铁图片,当我点击按钮我得到以下错误:

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类型的未捕获异常终止

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

Ama*_*mar 8

您正在发布actionBar实例并保留其实例view.如果actionBar实例响应按钮操作,则按钮单击消息将被发送到已删除的实例.您应该保留actionBar实例.一种方法是将它变成伊娃或retain财产.

您还可以创建UIViewController一个自定义视图.相反,您可以UIView使用其XIB 创建一个自定义.

编辑

声明保留财产,

@property (nonatomic, retain) ActionBarWithLogoff *actionBar;
Run Code Online (Sandbox Code Playgroud)

要么

简单地声明为ivar,

@interface YourViewController: UIViewController {
    ActionBarWithLogoff *actionBar;
}
Run Code Online (Sandbox Code Playgroud)

dealloc方法中,

-(void) dealloc {
    //...

    [actionBar release];

    //...
}
Run Code Online (Sandbox Code Playgroud)

希望有所帮助!