accessing a method from a button within a class?
Posted
by flo
on Stack Overflow
See other posts from Stack Overflow
or by flo
Published on 2010-05-29T14:37:46Z
Indexed on
2010/05/29
14:42 UTC
Read the original article
Hit count: 289
#import "GameObject.h" #import "Definitions.h"
@implementation GameObject
@synthesize owner;
@synthesize state;
@synthesize mirrored;
@synthesize button;
@synthesize switcher;
- (id) init {
if ( self = [super init] ) {
[self setOwner: EmptyField];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[self setSwitcher: FALSE];
}
return self;
}
- (UIButton*) display{
button.frame = CGRectMake(0, 0, GO_Width, GO_Height);
[button setBackgroundImage:[UIImage imageNamed:BlueStone] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed:)
forControlEvents:UIControlEventTouchUpInside];
return button;
}
-(void)buttonPressed:(id) sender {
//...
}
}
- (void) dealloc {
[super dealloc];
}
@end
Hi!
i would like to know if the above is possible somehow within a class (in my case it is called GameObject) or if i HAVE to have the button call a methode in the viewcontroller... the above results with the app crashing.
i would call display within a loop on the viewcontroller and id like to change some of the GameObjects instance variables within buttonPressed. Also id like to change some other stuff by calling some other methods from within buttonPressed but i think that will be the lesser of my problems ;)
also id like to know how i can pass some variables to the buttonPressed method... cant find it anywhere :( help on this one would be much appreciated ;)
thanks flo
© Stack Overflow or respective owner