Re: Calculations in a tableview
Re: Calculations in a tableview
- Subject: Re: Calculations in a tableview
- From: Quincey Morris <email@hidden>
- Date: Thu, 28 Jul 2011 20:15:14 -0700
On Jul 28, 2011, at 20:00, Andre Masse wrote:
> Is this can be done using bindings or should I stop fighting the framework and and use a datasource?
It can be done with bindings***. All you've done is clarified that "totalPrice" isn't a derived property after all. So, you make a regular property (with getter and setter), and initialize the instance variable that backs it to the default value (items * price).
Or, you can initialize the instance variable to a "not set" value (like 0 or NSNotFound, or something), but then you won't be able to just @synthesize the property -- you'll have to write code to return either the default or the explicit value, depending on the contents of the instance variable. (Or, you can have a BOOL instance variable that says whether the default has been overridden, but in that case you'll have to add code to the setter instead.)
And, incidentally, what you are trying to do is in no way "fighting" the framework. You're doing exactly what you're supposed to be doing. :)
*** Again, focus your thinking on *properties*. Ask yourself what properties your data model needs to support the user interaction, and it should become immediately clear what to do. Bindings are a way of hooking up (in this case) your UI to your data model's properties. They don't replace the data model design part of the process.
_______________________________________________
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