Reputation: 21
I'm having a problem with a checkbox. I want to set it to 0 (unchecked) on app launch, but the checkbox is controlled by another class "myClass" for example.
Here's what I did:
Here's the code for my myClass.m:
#import "myClass.h"
@implementation myClass
- (void) changeState
{
[myCheckbox setState:0];
}
@end
myClass.h
#import <Cocoa/Cocoa.h>
@interface myClass : NSObject {
IBOutlet NSButton *myCheckbox;
}
- (void) changeState;
@end
Then I made some changes in the AppDelegate files so they execute some things when the app is launched:
#import "UntitledAppDelegate.h"
#import "myClass.h"
@implementation UntitledAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
myClass * someClass = [[myClass alloc] init];
[someClass changeState];
}
@end
UntitledAppDelegate.h:
#import <Cocoa/Cocoa.h>
@interface UntitledAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
}
@property (assign) IBOutlet NSWindow *window;
@end
The purpose (if this works) is to set a value to the check box depending on the setting stored in the Defaults file.
The problem might be easy or too simple but I'm only a beginner...
Some help would be appreciated, Thanks !
Upvotes: 0
Views: 2141
Reputation: 21
- (void) awakeFromNib
{
[myCheckbox setState:0];
}
in myClass.m solved it.
Upvotes: 2