Problems with Check Boxes in NSTableView

Discussion in 'Mac Programming' started by LinusR, Oct 30, 2011.

  1. LinusR macrumors regular

    LinusR

    Joined:
    Jan 3, 2011
    #1
    Hi guys,

    I have an NSTableView with one column of check boxes. My Table view is full of entries which come from an NSArrayController. I use bindings. The NSArrayController is populated by a property list. These are the foundations.

    And here's my problem: The user can choose some entries with help of the check boxes. When you click on the "Go on"-button the entries with a TRUE-box have to be copied to a new NSArray.

    On the photo you can see the UI with my NSTableView.

    How can I get this done?

    Can anyone help?

    TIA,

    Linus
     

    Attached Files:

  2. Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #2
    In the Bindings Inspector:
    Link the Table Column's value (not the button cell's value)
    to arrangedObjects -> checkboxval (or appropriate variable you've set up in arrangedObjects).

    That's Table column value
    bind to: array controller
    controller key : arranged objects
    model key path: (checkboxval) your variable for the checkbox value

    You can retrieve the checkbox values from within your app as "checkboxval of arrangedObjects(n)" : where n goes from 1 to number of checkboxes.
     
  3. LinusR thread starter macrumors regular

    LinusR

    Joined:
    Jan 3, 2011
    #3
    @Partron22

    Thanks for your help. I did everything you said, but the last part... Could you put it into a code example?

    Thanks till now,

    Linus
     
  4. LinusR, Oct 31, 2011
    Last edited: Nov 1, 2011

    LinusR thread starter macrumors regular

    LinusR

    Joined:
    Jan 3, 2011
    #4
    I figured it out myself using this block of code:

    Code:
    - (IBAction)goon:(id)sender {
        
        NSMutableArray *titles = [NSMutableArray array];
        
        for (NSUInteger i = 0; i < [[myArrayController arrangedObjects] count]; i++) {
            NSDictionary *subDictionary = [[myArrayController arrangedObjects] objectAtIndex:i];
            if ([[subDictionary objectForKey:@"boxvalue"] isEqualToString:@"1"]) {
                [titles addObject:subDictionary];
            } else {
                NSLog(@"No Match");
            }
            
            NSLog([subDictionary objectForKey:@"boxvalue"]);
            NSLog(@"--------");
        }
        
        [titles writeToFile:@"/Users/apple/Desktop/titles.plist" atomically:YES];
    }
    
    
    @Partron22

    Thanks for your help, without you I wouldn't have got it.

    Have a nice day,

    Linus
     
  5. Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #5
    Excellent!
    In the end that's the only way to fly, but Obj C and XCode do both have nasty learning curves.
     

Share This Page