Re: Array controllers in code?
Re: Array controllers in code?
- Subject: Re: Array controllers in code?
- From: Amy Gibbs <email@hidden>
- Date: Thu, 22 Jul 2010 19:20:34 +0100
Fantastic, Thank You, got that bit working, just for reference I've
got the following:
@interface ishop_AppDelegate : NSObject
{
IBOutlet NSWindow *window;
IBOutlet NSArrayController *Products;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
NSManagedObjectModel *managedObjectModel;
NSManagedObjectContext *managedObjectContext;
}
/** Calculate Product Cost */
- (IBAction)calcCost:(id)sender;
{
NSObject *Product;
double *price, *uom, *cost;
Product = [[Products selectedObjects] objectAtIndex:0];
price = [Product valueForKey:@"UOMcost"];
uom = [Product valueForKey:@"purchaseUOM"];
cost = uom/price;
[Product setValue:cost forKey:@"cost"];
}
although the actual calculation won't work, not sure why, example
values are price=8.8, uom=25, getting an error:invalid operands to
binary?
Thank you though, this will help me so much with this project,
On 22 Jul 2010, at 11:22AM, Jack Nutting wrote:
The simplest way is to create action methods in your controller class,
along with ivars for the array controllers you need to access,
something like this in the header:
@interface MyController : NSObject {
IBOutlet NSArrayController *masterController;
IBOutlet NSArrayController *detailController;
}
- (IBAction)calculate:(id)sender;
@end
Then hook things up in IB, and then implement the calculate: method,
using ivars to grab and set the values you need. I'd offer an example,
but I'm writing on an iPhone and this has taken enough time already!
;)
// jack
// http://nuthole.com
// http://learncocoa.org
On Thursday, July 22, 2010, Amy Gibbs <email@hidden>
wrote:
Hi,
Apologies in advance for being stupid!
I've got an app I'm trying to create, using Core Data, I created
the data model, and Dragged some of the interface into place in the
nib.
I've almost got the bindings sorted so it's got Array controllers
for all the entities, and it's pretty much displaying everything
correctly.
Some things I want to do though need to be actually coded, but how
do I reference the Arrays/Array controllers in the code? Do I need
to declare them? They aren't at the moment that I can see, but
somehow it's using them. All the tutorials I find either cover
everything in code (kind of Pre-Core Data) or do everything with
bindings.
For example, I've got an Entity called Product, with 3 properties,
UOMcost, purchaseUOM and cost. I want cost to = UOMcost/
purchaseUOM. I can't set this up in the datamodel, so I need to
calculate it. In my interface I've got a table with all the
products, and text boxes that show the data for the selected
product ( master/details display). I've added a 'calculate' button,
so now I just need to take the 2 properties from the selected
product, do the maths, and set the cost property with the result.
If anyone could show me how to do this I'd be extremely grateful,
I'm only trying to do this for my own use, not to sell apps or
anything, and it would really help click some cocoa/Obj-C things
into place for me I think.
Thank You,
_______________________________________________
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
--
// jack
// http://nuthole.com
// http://learncocoa.org
_______________________________________________
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