StackOverflow 上有一些问题,其中用户遇到了与我相同的问题。然而,他们的解决方案都不适合我的情况。 (看here https://stackoverflow.com/questions/1421793/normal-uibutton-causing-obj-stack-overflow-or-exc-bad-access-exception, here https://stackoverflow.com/questions/5712957/uibutton-exc-bad-access-error, here https://stackoverflow.com/questions/2801103/ibaction-uibutton-and-exc-bad-access and here https://stackoverflow.com/questions/2070204/exc-bad-access-with-ibaction对于我读过但没有发现有帮助的一些问题。)
就我而言,我有一个 NIB,其中有几个UIButton
s,具有关联的控制器视图。该视图对于我的项目来说相对较旧,直到今天我才能够毫无问题地使用这些按钮。在进行了一些与按钮行为无关的代码更改后,我遇到了一个错误,导致应用程序崩溃,破坏了代码main()
函数并给我一个EXC_BAD_ACCESS
每当我触摸时都会出现错误消息any我的视图上的按钮。
如何或为何会发生这种情况?我实际上已经注释掉了几乎所有功能代码,尤其是我今天早些时候修改的代码,但我仍然无法阻止错误的发生。
我的项目正在使用自动引用计数,我以前没有见过这个错误。此外,我没有修改NIB,也没有修改IBAction
与按钮相关联,所以我不知道是什么导致了这种情况。停止错误的唯一方法是取消链接我的UIButton
在我的笔尖上IBAction
我的控制器视图头文件中定义的方法。
我的用例的唯一“独特”方面是我在另一个子视图控制器中加载此视图的一个或两个实例。加载的破碎视图实例的数量取决于数组中对象的数量。下面是我用来实例化这些视图并将其加载为另一个视图的子视图的代码。
//Called else where, this starts the process by creating a view that
//will load the problematic view as a sub-view either once or twice.
- (id)initWithPrimarySystemView:(SystemViewController *)svc
{
//First we create our parent, container view.
self = [super initWithNibName:@"ContainerForViewInstaniatedFromArrayObjs" bundle:nil];
if (self)
{
//Assign parent DataModel to local instance
[self setDataModel:((DataModelClass*)svc.DataModel)];
for (AnotherModel* d in DataModel.ArrayOfAnotherModels)
{
//Instantiate the SubViewController.
SubViewController* subsvc = [[SubViewController alloc]
initWithNibName:@"Subview"
bundle:nil
subviewPosition:d.Position ];
//Add the SubViewControllers view to this view.
[subsvc.view setFrame:CGRectMake((d.Position-1)*315, 0, 315, 400)];
[self.view addSubview:subsvc.view];
}
[self setDefaultFrame: CGRectMake(0, 0, 640, 400)];
}
return self;
}
这工作得很好,以前甚至没有对关联视图上的按钮造成任何麻烦,但是现在所有UIButton
点击时会使应用程序崩溃。
SubViewController的初始化函数,以及viewDidLoad
方法只包含创建新 ViewController 时添加的标准自动生成代码。
我可以做什么来解决或诊断这个问题?