Checkbox setState:0 on app launch
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:
- I opened Interface Builder and put a checkbox (NSButton) in my window, dragged NSObject in my MainMenu.xib window, renamed it to say "myClass". Added an outlet called "myCheckbox" (NSButton) and linked it to the checkbox I created earlier. Finally, I added some things.
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 "myCl开发者_JAVA技巧ass.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 !
- (void) awakeFromNib
{
[myCheckbox setState:0];
}
in myClass.m solved it.
精彩评论