PDA

View Full Version : How to use check buttons




DavidBlack
Mar 5, 2013, 09:19 PM
I am a developer newbie and I want when I check button when its on a on states to do this: -(IBAction)Purge:(id)sender{

NSString* path = [[NSBundle mainBundle] pathForResource:@"TurnOn 2d Dock" ofType:@"scpt"];
NSURL* url = [NSURL fileURLWithPath:path];NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
[appleScript executeAndReturnError:nil];


}

when the check button is in off state i want it to do this :
NSString* path = [[NSBundle mainBundle] pathForResource:@"TurnOff 2d Dock" ofType:@"scpt"];
NSURL* url = [NSURL fileURLWithPath:path];NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
[appleScript executeAndReturnError:nil];

how do i do this thanks in advance please I really want to make this app.
Also check out my software on: https://www.macupdate.com/developers/profile/



Red Menace
Mar 5, 2013, 09:52 PM
Just set an action for the checkbox, and look at its value to determine which way to go.

DavidBlack
Mar 6, 2013, 04:46 AM
Just set an action for the checkbox, and look at its value to determine which way to go.

can you guide me or give me a little tutorial I am a newbie so can you give me it a little more in detail

gnasher729
Mar 6, 2013, 04:48 AM
can you guide me or give me a little tutorial I am a newbie so can you give me it a little more in detail

Step 1: Start Safari.
Step 2: Type "cocoa tutorials" into the search box.

DavidBlack
Mar 6, 2013, 04:56 AM
Step 1: Start Safari.
Step 2: Type "cocoa tutorials" into the search box.

I found this on youtube: http://www.youtube.com/watch?v=ca6q8jcc368
but that only applies for changing labels. I want to do a different action when its in off or no state

ArtOfWarfare
Mar 6, 2013, 02:04 PM
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

if (switchOutlet.state == NSOnState) {
// your on code here
} else {
// your off code here
}

If any of those terms are unfamiliar, google them.

(I'm assuming you already know enough C/Obj-C to figure out your on code and off code yourself.)

DavidBlack
Mar 6, 2013, 02:08 PM
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

if (switchOutlet.on) {
// your on code here
} else {
// your off code here
}

If any of those terms are unfamiliar, google them.

(I'm assuming you already know enough C/Obj-C to figure out your on code and off code yourself.)
thanks! I am going to upload some snapshots

DavidBlack
Mar 6, 2013, 02:12 PM
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

if (switchOutlet.state == NSOnState) {
// your on code here
} else {
// your off code here
}

If any of those terms are unfamiliar, google them.

(I'm assuming you already know enough C/Obj-C to figure out your on code and off code yourself.)

look at this i connected the button but...

DavidBlack
Mar 6, 2013, 02:14 PM
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

if (switchOutlet.state == NSOnState) {
// your on code here
} else {
// your off code here
}

If any of those terms are unfamiliar, google them.

(I'm assuming you already know enough C/Obj-C to figure out your on code and off code yourself.)

How do i add the action to the checkbox?

DavidBlack
Mar 6, 2013, 02:40 PM
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

if (switchOutlet.state == NSOnState) {
// your on code here
} else {
// your off code here
}

If any of those terms are unfamiliar, google them.

(I'm assuming you already know enough C/Obj-C to figure out your on code and off code yourself.)
Sorry about that I got it to work but I also want the app to remember what button the user selected when the app quits how do I do that? I really appreciate your help

gnasher729
Mar 6, 2013, 03:46 PM
Sorry about that I got it to work but I also want the app to remember what button the user selected when the app quits how do I do that? I really appreciate your help

Xcode, Command-Shift-2, Documentation, search for "NSUserDefaults".

DavidBlack
Mar 7, 2013, 07:15 AM
Xcode, Command-Shift-2, Documentation, search for "NSUserDefaults".

i will have to look at theses methods:
- standardUserDefaults
- boolForKey:
- setBool:forKey:
I just want guidance on how to set the check button to save its on or off state when the user quits the app. Thank you anyone can help me?

Ap0ks
Mar 7, 2013, 07:34 AM
I just want guidance on how to set the check button to save its on or off state when the user quits the app. Thank you anyone can help me?Have a read of this Apple document (https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/UserDefaults/AccessingPreferenceValues/AccessingPreferenceValues.html#//apple_ref/doc/uid/10000059i-CH3-SW1) it contains useful information and examples for what you're trying to do.