• 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
Bindings and object-pointer keys
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bindings and object-pointer keys


  • Subject: Bindings and object-pointer keys
  • From: Seth Pellegrino <email@hidden>
  • Date: Sun, 30 Dec 2007 11:40:43 -0500

Hello list,

I'd like to apologize in advance for the length of this email; I would greatly appreciate any help anyone can give me.

I've built a test case for the problem I'm having, available here (should be both Tiger and Leopard friendly):

http://beta.darknoon.com/seth/TestBindings.zip

If you were unwilling/unable to download the project, the setup is as follows. There is an array of 'Person' objects, each of whom has a name and a job. Each Job is uniquely defined by a title (i.e. two Jobs are considered equal if their title strings are equal) and has a salary. Every person who shares a job has a pointer to exactly the same job object. In other words, if we pretend -isEqualToJob is defined, "[[person1 job] isEqualToJob:[person2 job]]" would be logically equivalent to "[person1 job] == [person2 job]". Because of the shared nature of job objects, retitling all Secretaries as Office Assistants requires but one -setTitle: message, and changing salaries is just as easy.

In the main interface, there are two table views, both controlled by instances of NSArrayController. One shows employees, the other displays jobs. The employees table view has three columns, name (bound to arrangedObjects.name), title (arrangedObjects.job.title), and salary (arrangedObjects.job). The salary column uses a custom 'SalaryCell' which extracts a job's salary from a Job instance (hence the unusual binding). In some "future version," this will be necessary so the SalaryCell can draw itself differently to indicate different jobs.

Phew, time to discuss the actual problem. Simply put, changes made to salaries in the job table are not reflected in the employees table without a forced refresh. To see this, simply create ('Hire') a person, use the pop up menu to set their job, and then try to change their salary. The salary column won't update until the next time the employees table becomes key.

The reason for this problem is also rather simple -- technically, the person's job property (to which the 'salary' table column is bound) doesn't change. It's still a pointer to the exact same memory location. However, the object at the other end of that pointer has changed. Is there some way to make the bindings mechanism aware of that fact? The options I see are a) somehow track that changes have been made to a job object and then programmatically force the table to refresh, or b) just throw up my hands and switch to using Core Data.

Is there a more elegant solution I'm missing? Failing that, which of the above options would you recommend?

Thank you for taking the time to read this email,

Seth Pellegrino
_______________________________________________

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: Bindings and object-pointer keys
      • From: Ken Thomases <email@hidden>
    • Re: Bindings and object-pointer keys
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Link (dyld) error: bad external relocation length
  • Next by Date: Re: Bindings and object-pointer keys
  • Previous by thread: Link (dyld) error: bad external relocation length
  • Next by thread: Re: Bindings and object-pointer keys
  • Index(es):
    • Date
    • Thread