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.
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:
thank u so so much it works like magic
i hope i am not bothering but could u tell me where or when exactly did the pool get drained ?? and what other types behaves the same ?is it every NS,every UI???
and if u don't have time just please point me to any reference or article or any link. you have already helped more than enough
again thanks a lot i hope i can return the favor someday.
thank u so so much it works like magic
i hope i am not bothering but could u tell me where or when exactly did the pool get drained ?? and what other types behaves the same ?is it every NS,every UI???
and if u don't have time just please point me to any reference or article or any link. you have already helped more than enough
again thanks a lot i hope i can return the favor someday.