[英]Program received signal EXC_BAD_ACCESS
When i click on done button which has code 当我单击具有代码的完成按钮时
UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(dismissView:)] autorelease];
self.navigationItem.rightBarButtonItem=UIBarButtonSystemItemDone;
[[self navigationItem] setRightBarButtonItem:button];
[button release];
-(void)dismissView: (id)sender
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
application crashes and gives message Program received signal EXC_BAD_ACCESS 应用程序崩溃并给出消息程序收到信号EXC_BAD_ACCESS
Any ideas what is wrong. 任何想法有什么问题。
Thanks for help. 感谢帮助。
This line is entirely wrong: 这行是完全错误的:
self.navigationItem.rightBarButtonItem=UIBarButtonSystemItemDone;
Remove it. 去掉它。 You are setting the
rightBarButtonItem
right after that and also, you can't set the rightBarButtonItem
to UIBarButtonSystemItemDone
- that just doesn't make any sense at all. 之后,您要设置
rightBarButtonItem
,也不UIBarButtonSystemItemDone
rightBarButtonItem
为UIBarButtonSystemItemDone
,这根本没有任何意义。
Oh and you're overreleasing button
. 哦,您在释放
button
。 Remove the [button release];
拆下
[button release];
as well. 也一样
You are over-releasing your button. 您过度释放了按钮。 You autorelease it when you alloc/init and then release it again after setting it as the nav item.
您在分配/初始化时自动释放它,然后在将其设置为导航项后再次释放它。
You're over-releasing button
. 您正在过度释放
button
。 Its +alloc
call on the first line is already balanced by the -autorelease
on that same line—you don't need to call -release
on it thereafter. 第一行的
+alloc
调用已经由同一行的-autorelease
平衡了, -autorelease
您无需在其上调用-release
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.