从超级视图中删除时 EXC_BAD_ACCESS
我的项目使用ARC,所以我不能使用保留或释放,在ViewController A中,我初始化ViewController B并将其视图添加为子视图:
ViewControllerB *viewB = [[ViewControllerB alloc] init];
[self.view addSubview:viewB.view];
在ViewControllerB中,我制作一个按钮,当用户单击它时,视图将被删除来自超级视图:
[self.view removeFromSuperview];
结果是 EXC_BAD_ACCESS。 请帮助我,对我的英语感到抱歉。
My project using ARC, so I can't use retain nor release, in ViewController A, I init ViewController B and add its view as a subview:
ViewControllerB *viewB = [[ViewControllerB alloc] init];
[self.view addSubview:viewB.view];
And in ViewControllerB, I make a button and when user click on it, the view will removed from superview:
[self.view removeFromSuperview];
And the result is EXC_BAD_ACCESS.
Please help me and sorry about my English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 viewB 不是局部变量。
I think viewB is not local variable.
我也有同样的问题..
尝试这样的事情:
或者:
这不是一个好的做法,但也许你会发现内存泄漏错误...
如果您使用 ARC - 它不能保护您免受内存管理错误的影响...
如果出现问题,我很抱歉我的英语。
I have the same problem too..
Try something like this:
or:
It's not good practice, but maybe you will catch a memory leak error...
If you are using ARC - it doesn't protect you from memory management errors...
I'm sorry for my English if something wrong.