0

在我的一个 ViewControllers (ViewController A) 中,我有以下代码:

AlertViewController *aViewController = [[AlertViewController alloc] initWithNibName:@"AlertViewController" bundle:nil];
[self.view addSubview:[aViewController view]];
[self.view bringSubviewToFront:[aViewController view]];

在 AlertViewController 中,我有一个按钮,当用户单击它时,我有:

[self.view removeFromSuperview];

每当我单击按钮时,结果都是 EXC_BAD_ACCESS。我无法弄清楚问题所在。如果该信息有帮助,我的项目正在使用 ARC,并且 ViewController A 是导航控制器堆栈的一部分。

4

1 回答 1

1

这里的问题是 UIView 不拥有它的 UIViewController。在第一个代码块中,您通过将 UIView 添加到子视图来保留它,但让 UIViewController 消失。UIViewController 中的 UIView 是特殊的,你不能让这种情况发生。

确保创建 UIView 的 UIViewController 与视图一样长。

于 2012-07-30T22:31:47.593 回答