嘿所有,我有一个数组,其中包含我的应用程序中的所有.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等随机对象,我不知道它们来自何处。
所有帮助表示感谢,谢谢!
答案 0 :(得分:2)
您正在defaultSounds
中发布buildDrumTrigger
,所以当其他方法尝试访问它时,它会指向已经解除分配的数据。
EXC_BAD_ACCESS表示您正在尝试访问无法访问的内存,通常是因为您已经发布了该内存。
答案 1 :(得分:2)
你可能会保留DrumObject中的数组而不保留它,所以最终会被垃圾覆盖。