Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 5, 2013, 09:19 PM   #1
DavidBlack
macrumors Demi-God
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
How to use check buttons

I am a developer newbie and I want when I check button when its on a on states to do this:
Code:
-(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 :
Code:
   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/

Last edited by SandboxGeneral; Mar 6, 2013 at 12:14 PM. Reason: Added code tags
DavidBlack is offline   0 Reply With Quote
Old Mar 5, 2013, 09:52 PM   #2
Red Menace
macrumors regular
 
Join Date: May 2011
Location: Littleton, Colorado, USA
Just set an action for the checkbox, and look at its value to determine which way to go.
__________________
MacBook Pro / OS X Mavericks (10.9.2) / Xcode 5.1 / [and various (much) older stuff keeping dust off the shelves]
Red Menace is offline   0 Reply With Quote
Old Mar 6, 2013, 04:46 AM   #3
DavidBlack
Thread Starter
macrumors Demi-God
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by Red Menace View Post
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
DavidBlack is offline   0 Reply With Quote
Old Mar 6, 2013, 04:48 AM   #4
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by DavidBlack View Post
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.
gnasher729 is offline   0 Reply With Quote
Old Mar 6, 2013, 04:56 AM   #5
DavidBlack
Thread Starter
macrumors Demi-God
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by gnasher729 View Post
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
DavidBlack is offline   0 Reply With Quote
Old Mar 6, 2013, 02:04 PM   #6
ArtOfWarfare
macrumors 601
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

Code:
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.)
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Including the ones paired with other Macs on your network.
ArtOfWarfare is offline   0 Reply With Quote
Old Mar 6, 2013, 02:08 PM   #7
DavidBlack
Thread Starter
macrumors Demi-God
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by ArtOfWarfare View Post
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

Code:
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 is offline   0 Reply With Quote
Old Mar 6, 2013, 02:12 PM   #8
DavidBlack
Thread Starter
macrumors Demi-God
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by ArtOfWarfare View Post
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

Code:
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...
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-03-06 at 4.10.44 PM.png
Views:	17
Size:	449.6 KB
ID:	401064  
DavidBlack is offline   0 Reply With Quote
Old Mar 6, 2013, 02:14 PM   #9
DavidBlack
Thread Starter
macrumors Demi-God
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by ArtOfWarfare View Post
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

Code:
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?
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-03-06 at 4.13.07 PM.png
Views:	15
Size:	429.4 KB
ID:	401065  
DavidBlack is offline   0 Reply With Quote
Old Mar 6, 2013, 02:40 PM   #10
DavidBlack
Thread Starter
macrumors Demi-God
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by ArtOfWarfare View Post
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

Code:
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
DavidBlack is offline   0 Reply With Quote
Old Mar 6, 2013, 03:46 PM   #11
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by DavidBlack View Post
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".
gnasher729 is offline   0 Reply With Quote
Old Mar 7, 2013, 07:15 AM   #12
DavidBlack
Thread Starter
macrumors Demi-God
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by gnasher729 View Post
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?
DavidBlack is offline   0 Reply With Quote
Old Mar 7, 2013, 07:34 AM   #13
Ap0ks
macrumors regular
 
Join Date: Aug 2008
Location: Cambridge, UK
Quote:
Originally Posted by DavidBlack View Post
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 it contains useful information and examples for what you're trying to do.
Ap0ks is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 06:29 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC