目标C - 阵列处于(无效)函数可读但不是一个(IBAction为)
-
26-09-2019 - |
题
嘿好,我有保存所有我的应用程序的.AIF文件路径,我发现,通过使用mainBundle和资源的阵列。
此阵列需要向下传递通过2个视图控制器以到达它被实际使用。问题是,它要么崩溃或登录东西完全错误的。当我调试,我得到在崩溃的EXC_BAD_ACCESS笔记,但不能当我运行它通常它只是崩溃。
在此处,它工作的地方;
- (void)buildDrumTrigger {
defaultSounds = [[NSArray alloc] initWithObjects: @"kick_3", @"aif", @"snare_1", @"aif", @"HiHat_1", @"aif", @"ride_1", @"aif", @"crash_1", @"aif", @"crash_2", @"aif", @"crash_3", @"aif", @"wave_1", @"aif", nil];
self.DrumObject = [[DrumTrigger alloc] initWithSounds:defaultSounds:5:volumeBox];
[defaultSounds release];
NSLog(@"Possible Sounds: %@", DrumObject.possDrumSounds);
}
,返回的路径为此在fileName.aif一个长列表。你的想法。
...然而
// Change the current view to the options window.
- (IBAction)goToOptionsView {
NSLog(@"Loading options menu");
NSLog(@"DrumObject.drumSounds: %@", DrumObject.drumSounds);
NSLog(@"DrumObject.possDrumSounds: %@", DrumObject.possDrumSounds);
optionsViewController.soundBox2 = DrumObject.drumSounds;
optionsViewController.possDrumSounds = DrumObject.possDrumSounds;
[self presentModalViewController:optionsViewController animated:YES];
}
这片断导致系统崩溃。如果我注释掉它与possDrumSounds交易的部分,它工作正常。否则,它崩溃或以某种方式改变数组包含像UIViewControllers随机对象,我不知道他们来自哪里。
所有帮助表示赞赏,谢谢!
解决方案
您正在DrumObject的阵列内可能保持周围没有留住它,所以它最后还是会被覆盖的垃圾。
其他提示
您将要发布的defaultSounds
buildDrumTrigger
,因此通过时间的其他方法试图访问它,它指向已经被释放的数据。
EXC_BAD_ACCESS表明您要访问的内存,你不能访问,通常是因为你已经释放了。
不隶属于 StackOverflow