Re: What should be the same object doesn't seem to be
Re: What should be the same object doesn't seem to be
- Subject: Re: What should be the same object doesn't seem to be
- From: Fritz Anderson <email@hidden>
- Date: Tue, 2 Oct 2007 10:48:55 -0500
On 2 Oct 2007, at 9:39 AM, Paul Bruneau wrote:
//now rebuild the menu with the items from operationTypes
NSMenuItem *menuItem;
for (loop = [operationTypes count] - 1; loop >= 0; loop--)
{
menuItem = [menu insertItemWithTitle:[[[self operationTypes]
objectAtIndex:loop] operationTypeName]
action:@selector(operationTypeWasSelected:)
keyEquivalent:@""
atIndex:0];
//set the represented object of this new menu item to be the
appropriate operation type
[menuItem setRepresentedObject:[operationTypes objectAtIndex:loop]];
}
Then, when the user goes to assign an operationType from the above
menu to what I call an "OrderStep", this gets called (by the action:
specified above):
//called by the user selecting an operation type from the submenu
- (void)operationTypeWasSelected:(NSMenuItem *)menuItem;
{
NSLog(@"The operation was selected! %@", [menuItem
representedObject]);
[[self clickedObject] setOperationType:[menuItem representedObject]];
[stepView setNeedsDisplay:YES];
}
The problem is that even though the selection of the OperationType
from the menu seems to go just fine (for instance, the correct
information appears, showing the correct operation name on the
OrderStep), it appears that the OperationType object is actually not
the same object that was attached to the menu, but seems to be a
copy of it or something. If I compare them, I see that one of them
might be 0x3c8fe0 and the other might be 0x3d2bd0 (what are these?
they seem too short to be pointers to the objects)
The first question to ask is whether the inserted object is really not
the same as the selected object. Your sample code shows you log the
selected object, but not that you log the inserted object (just before
or after setRepresentedObject:).
The string representation of pointers is done through a format like
"%x", which would suppress leading zeroes in the address. Your
pointers don't look wrong to me.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden