0

我的项目使用 ARC,所以我不能使用保留或释放,在 ViewController A 中,我初始化 ViewController B 并将其视图添加为子视图:

ViewControllerB *viewB = [[ViewControllerB alloc] init];

[self.view addSubview:viewB.view];

在 ViewControllerB 中,我制作了一个按钮,当用户单击它时,该视图将从超级视图中删除:

[self.view removeFromSuperview];

结果是 EXC_BAD_ACCESS。请帮助我并对我的英语感到抱歉。

4

2 回答 2

0

我认为 viewB 不是局部变量。

于 2012-01-16T10:58:44.163 回答
0

我也遇到同样的问题..

尝试这样的事情:

NSLog("self.view retain count: %d", self.view.retainCount);
[self.view removeFromSuperview];
NSLog("self.view retain count: %d", self.view.retainCount);

或者:

NSLog("self.view.superview retain count: %d", self.view.superview.retainCount);
[self.view removeFromSuperview];
NSLog("self.view.superview retain count: %d", self.view.superview.retainCount);

这不是一个好习惯,但也许你会发现内存泄漏错误......如果你使用的是 ARC - 它不能保护你免受内存管理错误的影响......

如果我的英语有问题,我很抱歉。

于 2012-02-12T11:08:53.623 回答