我有一个带有导入的自定义操作栏的主屏幕。我在单独的 .xib 文件中创建了这个 actionBar,其中包含 .m 和 .h 文件。
我在我的actionBar.m中做了一些图形设置viewDidLoad
like backgroundColor
和一些其他的东西。
我也有一个按钮actionBar
我按照通常链接按钮的方式链接,带有IBAction
.
我将操作栏加载到主屏幕中,如下所示:
ActionBarWithLogoff *actionBar = [[ActionBarWithLogoff alloc] initWithNibName:@"ActionBarWithLogoff" bundle:nil];
[topBar addSubview:actionBar.view];
[actionBar release];
我的actionBar.h:
- (IBAction)ActionBarLogoff:(id)sender;
我的actionBars.m的方法:
-(void) ActionBarLogoff:(UIButton *)sender
{
NSLog(@"!!!!!!!!!!ActionBarLogoff");
}
这是我的错误钢图片,当我单击按钮时,我收到以下错误:
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 类型的异常
有谁能告诉我为什么吗?最重要的是能够帮我解决这个问题^^?
您正在释放actionBar
实例并只保留其view
. If actionBar
实例是按钮操作的响应者,然后按钮单击消息将发送到已删除的实例。您应该保留actionBar
实例。一种方法是将其设为 ivar 或retain
财产。
看起来您正在创建一个UIViewController
用于自定义视图。相反,您可以只创建一个自定义UIView
及其 XIB。
EDIT
声明保留财产,
@property (nonatomic, retain) ActionBarWithLogoff *actionBar;
OR
只需声明为 ivar,
@interface YourViewController: UIViewController {
ActionBarWithLogoff *actionBar;
}
And in dealloc
method,
-(void) dealloc {
//...
[actionBar release];
//...
}
希望有帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)