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

    #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

    #2
    Just set an action for the checkbox, and look at its value to determine which way to go.
     
  3. macrumors 6502a

    DavidBlack

    #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

    #4
    Step 1: Start Safari.
    Step 2: Type "cocoa tutorials" into the search box.
     
  5. macrumors 6502a

    DavidBlack

    #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

    #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. macrumors 6502a

    DavidBlack

    #7
    thanks! I am going to upload some snapshots
     
  8. macrumors 6502a

    DavidBlack

    #8
    look at this i connected the button but...
     

    Attached Files:

  9. macrumors 6502a

    DavidBlack

    #9
    How do i add the action to the checkbox?
     

    Attached Files:

  10. macrumors 6502a

    DavidBlack

    #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

    #11
    Xcode, Command-Shift-2, Documentation, search for "NSUserDefaults".
     
  12. macrumors 6502a

    DavidBlack

    #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

    #13
    Have a read of this Apple document it contains useful information and examples for what you're trying to do.
     

Share This Page