How to use check buttons

Discussion in 'Mac Programming' started by DavidBlack, Mar 5, 2013.

  1. DavidBlack, Mar 5, 2013
    Last edited by a moderator: Mar 6, 2013

    macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #1
    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/
     
  2. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    Just set an action for the checkbox, and look at its value to determine which way to go.
     
  3. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #3
    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
     
  4. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #4
    Step 1: Start Safari.
    Step 2: Type "cocoa tutorials" into the search box.
     
  5. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #5
    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
     
  6. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #6
    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.)
     
  7. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #7
    thanks! I am going to upload some snapshots
     
  8. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #8
    look at this i connected the button but...
     

    Attached Files:

  9. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #9
    How do i add the action to the checkbox?
     

    Attached Files:

  10. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #10
    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
     
  11. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #11
    Xcode, Command-Shift-2, Documentation, search for "NSUserDefaults".
     
  12. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #12
    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?
     
  13. macrumors regular

    Joined:
    Aug 12, 2008
    Location:
    Cambridge, UK
    #13
    Have a read of this Apple document it contains useful information and examples for what you're trying to do.
     

Share This Page