UIButton EXC_BAD_ACCESS错误 [英] UIButton EXC_BAD_ACCESS error

查看:58
本文介绍了UIButton EXC_BAD_ACCESS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UI按钮,按下后它可以正常工作. 但是,如果我按三次按钮,则会收到EXc_BAD_ACCESS错误. 我以为我在某个地方放了东西,但找不到解决方案. 请你帮助我好吗? 亲切的问候.

I have an UI button and it works correctly when I pressed. But if I press the button three times, I get an EXc_BAD_ACCESS error. I thought I release something in somewhere but I couldn't find the solution. Could you please help me? Kind regards.

这是我按下按钮时的功能.在解除分配时,我释放了它们.当我跟踪时,它不会给出函数错误.我是在函数之后得到它的,但是我不知道该函数之后的代码在哪里.

This is the function when I pressed the button. And in dealloc I release them. When I am tracking, it doesn't give the error in function. I got it after function, but I dont know where the code goes after this function.

- (IBAction) doSomething: (id)sender
{
    [self.answerDict replaceObjectAtIndex:currentPageNumber withObject:@"1"];
    [self.b setImage:nil forState:UIControlStateNormal];
    [self.c setImage:nil forState:UIControlStateNormal];
    [self.d setImage:nil forState:UIControlStateNormal];
    [self.e setImage:nil forState:UIControlStateNormal];        

    UIImage *img = [UIImage imageNamed:@"a.jpg"];
    [self.a setImage:img forState:UIControlStateNormal];
    [img release];
}

推荐答案

UIImage *img = [UIImage imageNamed:@"a.jpg"];
[self.a setImage:img forState:UIControlStateNormal];
[img release];

[img release];是问题.您正在释放一个您不拥有的对象. img在这种情况下会自动发布.

[img release]; is the problem. You are releasing an object which you dont own. img in this case is auto-released.

删除[img release];,看看是否发生了崩溃

Remove [img release]; and see if the crash occurs

这篇关于UIButton EXC_BAD_ACCESS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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