Custom class deallocated as soon as the app starts.

Posted by Tangrs on Stack Overflow See other posts from Stack Overflow or by Tangrs
Published on 2010-06-09T10:00:05Z Indexed on 2010/06/09 10:02 UTC
Read the original article Hit count: 162

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about dealloc