Quote:
Originally Posted by themaster
hello everyone
i was working on a simple game that in which some nsarrays must be initiated with some uibuttons .So i initialized it at the [view did load] later i schedule the main game loop the problem is when the method returns all these data are erased or somehow unexisting and ever since i try and access any of it's elements a runtime error raises (EXC_BAD_ACCESS)
like so:
NSArray *bees;
- (void)viewDidLoad {
[super viewDidLoad];
bees=[NSArray arrayWithObjects:[UIButton buttonWithType:UIButtonTypeRoundedRect],nil];
timer=[NSTimer scheduledTimerWithTimeInterval:1/60 target:self selector:@selector(gameloop) userInfo:nil repeats:YES];
}
-(void)gameloop{
UIButton *temp=[bees objectAtIndex:0];//problem here <----------------
}
sure i made the @synthesize and @proprety;
i ve been searching the internet looking for a solution on where exactly to initiate objects but all i could get is that there is a view did load and a init which i know nothing about
so please if anyone could tell me what's wrong or even point me to an article explaining the viewdidload and it's behavior and the init method
thanks in advance and i hope i can repay u someday.
|
You are creating autorelease array which is deleted when the pool is drained.
You need to retain the NSArray like this:
[[NSArray arrayWithObjects:[UIButton buttonWithType:UIButtonTypeRoundedRect],nil] retain];
Best regards!