I am initializing UIButton in init method of a class like this:
UIButton* upButton=[[UIButton alloc] initWithFrame:CGRectMake(2*stepX, 13*stepY,2*stepX,stepY)];
[upButton setTitle:@"UP" forState:UIControlStateNormal];
[upButton setBackgroundColor:[UIColor blueColor]];
[upButton addTarget:self action:@selector(pressedUp) forControlEvents:UIControlEventTouchUpInside];
In pressedUp method I need to use variables from that class (NSInteger* and my class hero*).
So I am doing:
hero*h=self.mainHero;
NSInteger*m=self.map;
But later in code I can easily work with hero class (change position etc) but it fails to work with self.map (awful integers in array instead of 0 and 1)… How to fix it?
From your last comment it appears that the problem is due to a dangling reference: you create a local variable
lvl1Map[], assign it toself.map, and exit the initializer. At this point,lvl1Map[]is gone, but themapis pointing to the area in the memory where it once has been.You can fix this problem by declaring
lvl1Mapstatic: