Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not at my Xcode computer right now, so i can't test this, but it seems like you don't really need another array controller, but just another array to hold the likedFruits. I think you need to create an array of dictionaries from your acquiredFruits array that would have one key for the fruit name and another key with a bool value for whether the check box is checked --this bool would be bound to your second column. I'm not sure about the next step on how to tell the likedFruit array that it need to add a new fruit -- I think the check box could have an action method that you could use to have the likedFruit array add the object in the row where the check box was clicked.</p> <p>After Edit:</p> <p>Here is an example of how to do what I suggested. I take an array of fruits and turn it into an array of dictionaries (called theData) that include a key for the value of your check box (In IB the content array of the array controller is bound to theData, and the columns are bound to Array Controller.arrangedObjects.fruitName and Array Controller.arrangedObjects.isLiked). checkChanged is an IBAction connected to the check box (but note the sender is actually the table view), and I use the value of the check box to determine whether to add a fruit to likedFruits or delete one. I put one more method, connected to a button just to check the values in likedFruits.</p> <pre><code>@implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.theData = [NSMutableArray array]; self.likedFruit =[NSMutableArray array]; NSArray *acquiredFruits = @[@"Apple",@"Orange",@"Pear",@"Peach"]; for (NSString *aFruit in acquiredFruits) { NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:aFruit,@"fruitName",[NSNumber numberWithBool:NO],@"isLiked", nil]; [self.theData addObject:[dict mutableCopy]]; } self.theData = _theData; // NSLog(@"%@",self.theData); } -(IBAction)checkChanged:(NSTableView *)sender { //connected to the button cell in the table view (but sender is the table view) NSString *theFruit = [[self.controller.arrangedObjects objectAtIndex:sender.clickedRow ] valueForKey:@"fruitName"]; BOOL doWeLikeIt = [[[self.controller.arrangedObjects objectAtIndex:sender.clickedRow] valueForKey:@"isLiked"] boolValue]; if (doWeLikeIt) { [self.likedFruit addObject:theFruit]; }else{ [self.likedFruit removeObject:theFruit]; } } -(IBAction)logLikedFruits:(id)sender { NSLog(@"%@",self.likedFruit); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload