small medium large xlarge

Generic-user-small
02 Mar 2011, 01:25
Michael Micelli (3 posts)

Tim,

On page 253 of p1.0, you write the tableView:setObjectValue:forTableColumn:row like so:

- (void)tableView:(NSTableView *)aTableView 
   setObjectValue:(id)anObject 
   forTableColumn:(NSTableColumn *)aTableColumn 
              row:(NSInteger)rowIndex {
    
    NSDictionary *itemDictionary = [shoppingListArray objectAtIndex:rowIndex];
    
    if (aTableColumn == quantityColumn) {
        [itemDictionary setValue:anObject forKey:@"itemQuantityKey"];
    }
    else if (aTableColumn == itemNameColumn) {
        [itemDictionary setValue:anObject forKey:@"itemNameKey"];
    }
    
    [shoppingListArray replaceObjectAtIndex:rowIndex withObject:anObject];
}

When I compile and try to edit a quantity or item name, the application freezes. The console shows the following: @Shopping List[49215:a0f] [<NSCFString 0x100425a50> valueForUndefinedKey:]: this class is not key value coding-compliant for the key itemQuantityKey.@

I’ve gone over and over the code making sure I have no typos, but I’m at a loss for what’s wrong…

Generic-user-small
02 Mar 2011, 09:35
Tim Isted (105 posts)

Hi Michael,

Have you definitely made the modifications shown to the init method on page 251 of p1.0?

At face value, the error in the console sounds like the shopping list is still made up of an array of string objects as it was earlier in the book—if you try to change the “itemQuantityKey” on a string object, you get the message shown.

When you run the application, are all the initial items and quantities shown correctly as specified in the init method?

Generic-user-small
02 Mar 2011, 16:47
Michael Micelli (3 posts)

Thanks for the response!

Checked the @init@ method. It matches page 251 exactly.

When the program starts, everything runs correctly. The list items and quantities are right.

It doesn’t freeze until I try to to edit.

Generic-user-small
02 Mar 2011, 20:15
Michael Micelli (3 posts)

Tim,

Found it.

For some reason my mind kept glossing over the last line in the function:

@[shoppingListArray replaceObjectAtIndex:rowIndex withObject:anObject];@

Once I removed it (as shown in the book) everything works fine.

I also had it in the @tableView:objectValueForTableColumn:row:@ function.

Sorry to have bothered you with my inattention to details :-P

Thanks for the snappy reply nonetheless.

You must be logged in to comment