Giving another object a NSManagedObject
- by Wayfarer
Alright, so I'm running into an issue with my code. What I have done is subclassed UIButton so I can give it some more infomormation that pertain to my code. I have been able to create the buttons and they work great. Capiche.
However, one of the things I want my subclass to hold is a reference to a NSMangedObject. I have this code in my header file:
@interface ButtonSubclass : UIButton {
NSManagedObjectContext *context;
NSManagedObject *player;
}
@property (nonatomic, retain) NSManagedObject *player;
@property (nonatomic, retain) NSManagedObjectContext *context;
- (id)initWithFrame:(CGRect)frame andTitle:(NSString*)title;
//- (void)setPlayer:(NSManagedObject *)aPlayer;
@end
As you can see, it has a instance variable to the NSMangedobject I want it to hold (as well as the Context). But for the life of me, I can't get it to hold that NSManagedObject. I run both the @synthesize methods in the Implementation file.
@synthesize context;
@synthesize player;
So I'm not sure what I'm doing wrong. This is how I create my button:
ButtonSubclass *playerButton = [[ButtonSubclass alloc] initWithFrame:frame andTitle:@"20"]; //works
playerButton.context = self.context; //works
playerButton.player = [players objectAtIndex:i]; //FAILS
And I have initilaized the players array earlier, where I get the objects. Another weird thing is that when it gets to this spot in the code, the app crashes (woot) and the the console output stops. It doesn't give me any error, and notification at all that the app has crashed. It just... stops. So I don't even know what the error is that is crashing the code, besides it has to do with that line up there setting the "player" variable. Thoughts and ideas? I'd love your wisdom!