views:

59

answers:

1

Heya,

I've added a class object to the nib file. All connections are made.

But for some reason, the object is deallocated as soon as it's created.

Here's the code:

control.h:

#import <Foundation/Foundation.h>
@interface control : NSObject 
{
    IBOutlet UILabel *PlayerScore;
}
-(IBAction) addPoint: sender;
-(void) dealloc;
@end

control.m:

#import "control.h"
@implementation control
-(IBAction)addPoint: sender {
    NSLog(@"Ohhai. Didn't crash."); //Doesn't even make it to this stage.
    int i = [PlayerScore.text intValue];
    PlayerScore.text=[NSString stringWithFormat: @"%d",++i];
}
-(void) dealloc {
    NSLog(@"ZOMGWTF?");
    [super dealloc];
}
@end

Here is the console log:

[Session started at 2010-06-09 19:47:57 +1000.]
2010-06-09 19:47:58.771 App[91100:207] ZOMGWTF?

And after I click the button which messages addPoint, of course, it crashes.

2010-06-09 19:47:59.703 App[91100:207] * -[control] performSelector:withObject:withObject:]: message sent to deallocated instance 0x3843d80

Does anyone have any ideas?

A: 

Try changing control.h to be:

#import <Foundation/Foundation.h>
@interface control : NSObject 
{
    UILabel *PlayerScore;
}
@property (nonatomic, retain) IBOutlet UILabel *PlayerScore;
-(IBAction) addPoint: sender;
-(void) dealloc;
@end

And then add a @synthesize to the implementation section of 'control'.

Also, who has reference to the control class in the NIB?

Frank C.
Tried that but it still gets deallocated at runtime.control has no reference outlets connected.
Tangrs
Connect the reference to the File Owner... I assume you are building with the Garbage Collector. With no reference to hold the 'control' object to the GC is sweeping it away.
Frank C.