Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

LinusR

macrumors 6502
Original poster
Jan 3, 2011
334
515
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
 

Attachments

  • Demo-Picture.png
    Demo-Picture.png
    153.9 KB · Views: 126
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.
 
@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
 
@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

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
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.