使用xcode 4.2导致访问异常 [英] Bad access exception using xcode 4.2
本文介绍了使用xcode 4.2导致访问异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
触摸按钮调用按钮操作时,我收到 EXC_BAD_ACCESS
。
I am getting "EXC_BAD_ACCESS
" when touch the button to call the button action.
#import "TestViewController.h"
@implementation TestViewController
- (id)init
{
self = [super init];
if (self)
{
self.title=@"IOS5 and Xoced 4.2";
UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(9,6,100,100)];
button.backgroundColor=[UIColor greenColor];
[button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: button];
}
return self;
}
-(void)viewWillAppear:(BOOL)animated
{
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithTitle:@"Add"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(addAction)];
self.navigationItem.rightBarButtonItem = addButton;
}
-(void)buttonAction
{
printf("Hi i am in buttonAction method");
}
-(void)addAction
{
printf("Hi i am in addAction method");
}
我使用了 ARC enbled 这个项目。
当我触摸UIBarButtonItem或UIButton时,我收到以下错误。
I used ARC enbled in this project. When I touch the UIBarButtonItem or UIButton I am getting below error.
TestXcode4 [2470:207] - [__ NSCFString addAction] :无法识别的选择器
发送到实例0x6827b00
TestXcode4[2470:207] -[__NSCFString addAction]: unrecognized selector sent to instance 0x6827b00
请帮我解决这个问题。
推荐答案
如果将此视图控制器添加到窗口,则在addsubview调用后不会释放该控制器。因为窗口不会保留该视图控制器。
If you add this view controller to the window then you don't release that controller after addsubview call. Because window will not retain that view controller.
这篇关于使用xcode 4.2导致访问异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文