我不完全相信如果我写这个数组是正确的。这是我的应用程序委托中的.h。NSArray得到一个EXC_BAD_ACCESS
NSString *text0;
...
NSString *text123;
NSMutableArray *fortunesArray;
}
@property(nonatomic,retain) NSMutableArray *fortunesArray;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet AppViewController *viewController;
@end
然后在应用程序的delegate.m中,我将它们全部指定为这样。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
text0 = @"Text here";
...
text123 = @"Text here";
self.fortunesArray = [NSMutableArray arrayWithObjects:text0,text1,text2,text3,text4,text5,text6,text7,text8,text9,text10,text11,text12,text13,text14,text15,text16,text17,text18,text19,text20,text21,text22,text23,text24,text25,text26,text27,text28,text29,text30,text31,text32,text33,text34,text35,text36,text37,text38,text39,text40,text41,text42,text43,text44,text45,text46,text47,text48,text49,text50,text51,text52,text53,text54,text55,text56,text57,text58,text59,text60,text61,text62,text63,text64,text65,text66,text67,text68,text69,text70,text71,text72,text73,text74,text75,text76,text77,text78,text79,text80,text81,text82,text83,text84,text85,text86,text87,text88,text89,text90,text91,text92,text93,text94,text95,text96,text97,text98,text99,text100,text101,text102,text103,text104,text105,text106,text107,text108,text109,text110,text111,text112,text113,text114,text115,text116,text117,text118,text119,text120,text121,text122,text123,nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
我与NSArray的和可变的尝试这样做。 EXC_BAD_ACCESS显示指向text3,并指向text5之前。如果我在大约50分钟后切出所有内容,屏幕将会打开,但是当我最终尝试通过单击按钮来使其工作时,它会回到那个不好的访问。 (所以不能分辨是否有视图按钮的问题,因为这个问题在这个数组上重复发生。)我会发布调用它的代码,但我很确定主要问题有些事情要做与这个数组。
在我看来Controller.m或者
-(IBAction)ganjaButton:(id)sender{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
int pressCount;
NSString *display;
if(pressCount%2==0){
[sender setBackgroundImage:[UIImage imageNamed:@"nug2.png"] forState:UIControlStateNormal];
display = [[NSString alloc] initWithFormat:@"%@",[appDelegate.fortunesArray objectAtIndex:40]];
}
else{
[sender setBackgroundImage:[UIImage imageNamed:@"nug1.png"] forState:UIControlStateNormal];
display = [[NSString alloc] initWithFormat:@"%@",[appDelegate.fortunesArray objectAtIndex:44]];
}
pressCount++;
label.text = display;
[display release];
}
而且是在上面的代码,说的AppDelegate的部分实际上是我的AppDelagtes名字。
任何帮助,将不胜感激。谢谢。
是'fortunesArray'综合还是你用自己的方法包装它?你还可以指出你会遇到哪种情况? (是“自我”吗?fortunesArray = [NSMutableArray arrayWithObjects:text0..'?) –
它被合成。 – steven
尝试打开NSZombies并检查是什么原因导致EXC_BAD_ACCESS - 这样它会指向你释放的对象。代码看起来很好,我认为,即使有这么大的昏迷分离值,我不想在我的代码中看到;-)。启用NSZombies:http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-on-xcode-4 – Mayjak