0
votes

i have a program that i am writing that has a table view with two columns. one of then is for a customer name and the other one is for an ID which has to be generated randomly when a new customer is created using core data.

I have so far been able to generate a random number but i have no idea on how to insert into the id column when a new customer is created. as i am using the add action from the nsarraycontroller i can't give the button the command to do it. here is my code that makes the number:
int number = arc4random() %(100);
this is the code that i have in my .m file

import Foundation/Foundation.h
include stdlib.h

@interface tableViewData : NSObject{

IBOutlet NSTextField *randomeNumber;
IBOutlet NSTableColumn *customerId;
IBOutlet NSTableColumn *customerName;

}
- (IBAction)numer:(id)sender;
- (IBAction)customerID:(id)sender;

any help would be appreciated

thanks
G
p.s. i am using Xcode 4.2.1 and programming for osx

1
Could you please post some more code and format it?Axel
int number = arc4random() %(100); this is the only code that i have to make the random number. i need to be able to put it into a column in my table view every time i create a new customer? sorry i don't know how to format here i am new to SOuser1318998

1 Answers

0
votes

The random ID should be generated by the class representing the customer, which would presumably be a subclass of NSManagedObject. In other words, the customer should initialize itself. You can override -awakeFromInsert to do that. The docs for that method say "You typically use this method to initialize special default property values."