Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 5, 2013, 10:19 PM   #1
DavidBlack
macrumors 6502
 
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 01:14 PM. Reason: Added code tags
DavidBlack is offline   0 Reply With Quote
Old Mar 5, 2013, 10:52 PM   #2
Red Menace
macrumors 6502
 
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 Yosemite (10.10) / Xcode 6.1 / RubyMotion FTW
Red Menace is offline   0 Reply With Quote
Old Mar 6, 2013, 05:46 AM   #3
DavidBlack
Thread Starter
macrumors 6502
 
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, 05: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, 05:56 AM   #5
DavidBlack
Thread Starter
macrumors 6502
 
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, 03:04 PM   #6
ArtOfWarfare
macrumors 603
 
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.)
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Mar 6, 2013, 03:08 PM   #7
DavidBlack
Thread Starter
macrumors 6502
 
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, 03:12 PM   #8
DavidBlack
Thread Starter
macrumors 6502
 
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:	32
Size:	449.6 KB
ID:	401064  
DavidBlack is offline   0 Reply With Quote
Old Mar 6, 2013, 03:14 PM   #9
DavidBlack
Thread Starter
macrumors 6502
 
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:	28
Size:	429.4 KB
ID:	401065  
DavidBlack is offline   0 Reply With Quote
Old Mar 6, 2013, 03:40 PM   #10
DavidBlack
Thread Starter
macrumors 6502
 
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, 04: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, 08:15 AM   #12
DavidBlack
Thread Starter
macrumors 6502
 
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, 08: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

Similar Threads
thread Thread Starter Forum Replies Last Post
How to check log files to date/time system RAM was changed? Any way to check this? asterix2k10 OS X 1 Mar 7, 2014 09:19 PM
iPhone 5 buttons oililymad iPhone 10 Jan 24, 2013 11:59 AM
The I may go to bed, and just check back in tomorrow to check my order status thread lsutigerfan1976 iPhone 0 Sep 14, 2012 11:50 PM
Check List++ (World most intuitive and fastest check list) - Free App appinitpro iPhone and iPod touch Apps 5 Jun 16, 2012 12:31 AM

Forum Jump

All times are GMT -5. The time now is 04:42 PM.

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

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