• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
What should be the same object doesn't seem to be
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What should be the same object doesn't seem to be


  • Subject: What should be the same object doesn't seem to be
  • From: Paul Bruneau <email@hidden>
  • Date: Tue, 2 Oct 2007 10:39:20 -0400

Hi there-

I have a problem where the object that I choose from a contextual menu that I custom-build does not seem to be the same object that is later chosen from that menu by the user. Additionally, it makes me wonder if I'm making a mistake in my way of thinking about how I'm doing things on a larger scale.

This is a scheduling program. What is happening is that the user is right-clicking on a graphical representation of what I call an "OrderStep" to choose what type of operation (OperationType) is required to perform the work on the OrderStep.

First I build the contextual menu in a menuNeedsUpdate method like this: (note that I use representedObject to link the menu item to the corresponding operationType)

//first, remove all items except for the last 2 (which are "edit..." and the separator line)
int loop;
for (loop = [menu numberOfItems] - 3; loop >= 0; loop--)
{
[menu removeItemAtIndex:loop];
}

//sort the array
NSSortDescriptor *descriptor = [[[NSSortDescriptor alloc] initWithKey:@"operationTypeCode" ascending:YES] autorelease];
NSArray *descriptors = [NSArray arrayWithObjects:descriptor, nil];
[operationTypes sortUsingDescriptors:descriptors];

//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 reason i have to compare them is to see if a given WorkCenter can perform the work required by the OrderStep. The problem is that the WorkCenter's OperationType (the type of work it can do) object is not the same as the OrderStep's OperationType (the type of work it needs done) even though to my mind they should be exactly the same.

I'm afraid I have poorly presented this, but it's my best at this time. If anyone can throw any ideas my way, I'm very grateful.

Maybe I shouldn't be comparing the actual objects, but instead I should be comparing something more basic held within the object (each OperationType has an operationTypeCode which is an Int to give the user a numeric representation of the operation type). Maybe I should compare that?
_______________________________________________


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


  • Follow-Ups:
    • Re: What should be the same object doesn't seem to be
      • From: Fritz Anderson <email@hidden>
  • Prev by Date: Re: Problems with authorization (error -60002, errAuthorizationInvalidRef)
  • Next by Date: CoreData model optimization? (slow on insert with fetches)
  • Previous by thread: Re: CoreData - How to monitor progress during long fetch ?
  • Next by thread: Re: What should be the same object doesn't seem to be
  • Index(es):
    • Date
    • Thread