首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >目标C-数组在(空)函数中是可读的,但在(IBAction)函数中是不可读的

目标C-数组在(空)函数中是可读的,但在(IBAction)函数中是不可读的
EN

Stack Overflow用户
提问于 2010-09-03 07:46:05
回答 2查看 175关注 0票数 1

嘿,我有一个数组,它保存了我的应用程序中的所有.aif文件路径,这是我通过使用mainBundle和资源找到的。

这个数组需要通过两个视图控制器向下传递,才能到达实际使用的位置。问题是,它要么崩溃,要么记录一些完全错误的东西。当我调试时,我在崩溃时得到了一个EXC_BAD_ACCESS注释,但当我正常运行它时,它就崩溃了。

这就是它发挥作用的地方;

代码语言:javascript
复制
- (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结尾的路径的长列表。你明白了吧。

然而..。

代码语言:javascript
复制
// 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这样的随机对象,我不知道它们来自哪里。

感谢大家的帮助,谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-09-03 07:51:26

您可能会将数组保留在DrumObject中而不保留它,因此它最终会被垃圾所覆盖。

票数 2
EN

Stack Overflow用户

发布于 2010-09-03 07:49:51

您将在buildDrumTrigger中释放defaultSounds,因此当其他方法尝试访问它时,它会指向已释放的数据。

EXC_BAD_ACCESS表明你正在尝试访问你不能访问的内存,通常是因为你已经释放了它。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3632095

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档