在我的一个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是导航控制器堆栈的一部分,如果该信息有帮助。
答案 0 :(得分:1)
这里的问题是UIView没有自己的UIViewController。在第一个代码块中,您通过将UIView添加到子视图来保持UIView,但让UIViewController消失。来自UIViewController的UIView很特别,你不能让这种情况发生。
确保创建UIView的UIViewController与视图一样长。