Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get information of an object instance from ID number
    primarykey
    data
    text
    <p>I have a program that has 2 tables on two different windows. One table holds the customer name and id number and the other one hold the item name and number. They are both stored in a array and also in a .plist file.</p> <p>What i would like to do is that on a third page there is going to be a sales page where the user will enter the customer id and item id and the program should be able to find the name and display it to a label. I don't know where to start and go. Could somebody please help or show me how to do i? I can upload any code that anybody wants to see but as I dont know where to start I dont know what to upload.<br> this is the customer.h file </p> <pre><code>#import &lt;Foundation/Foundation.h&gt; NSString *name; int memberNumber; @interface Customer : NSObject &lt;NSCoding&gt; { NSString *name; int memberNumber; } @property (nonatomic, copy) NSString *name; @property int memberNumber; @end </code></pre> <p>this is the customer.m </p> <pre><code>#import "Customer.h" @implementation Customer @synthesize name; @synthesize memberNumber; -(id) init { self = [super init]; if(self) { name = @"Test"; int i = arc4random()%1000000000000000000; if (i&lt;0) { memberNumber = i*-1; } else memberNumber = i; } return self; } - (id)initWithCoder:(NSCoder *)decoder { if (self = [super init]) { self.name = [decoder decodeObjectForKey:@"name"]; self.memberNumber = [decoder decodeIntForKey:@"memberNumber"]; } return self; } - (void)encodeWithCoder:(NSCoder *)encoder { [encoder encodeObject:name forKey:@"name"]; [encoder encodeInt:memberNumber forKey:@"memberNumber"]; } -(void)dealloc { [name release]; [super dealloc]; } @end </code></pre> <p>this is the tableView.h file </p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #include &lt;stdlib.h&gt; NSString *filepath; @interface tableViewData : NSObject &lt;NSTableViewDataSource&gt; { @private IBOutlet NSTableView *tableView; NSMutableArray *list; NSString *filepath; } -(IBAction)add:(id)sender; -(IBAction)remove:(id)sender; @end </code></pre> <p>this is the tableView.m file</p> <pre><code>#import "tableViewData.h" #import "Customer.h" @implementation tableViewData -(void)awakeFromNib{ filepath = @"/Users/Desktop/CustomerNames.plist"; if ([[NSFileManager defaultManager]fileExistsAtPath:filepath]) { NSMutableArray *archive = [NSKeyedUnarchiver unarchiveObjectWithFile:filepath]; list = archive; } else list=[[NSMutableArray alloc]init]; } -(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { return [list count]; } -(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { Customer *Customer = [list objectAtIndex:row]; NSString *identifier = [tableColumn identifier]; return [Customer valueForKey:identifier]; } -(void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn: (NSTableColumn *)tableColumn row:(NSInteger)row { Customer *Customer = [list objectAtIndex:row]; NSString *identifier = [tableColumn identifier]; [Customer setValue:object forKey:identifier]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:list]; [data writeToFile:filepath options:NSDataWritingAtomic error:nil]; } -(IBAction)add:(id)sender { [list addObject:[[Customer alloc]init]]; [tableView reloadData]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:list]; [data writeToFile:filepath options:NSDataWritingAtomic error:nil]; for (id name in list) NSLog(@"obj: %@", name); NSLog (@"array:%@",list); } -(IBAction)remove:(id)sender { NSInteger row = [tableView selectedRow]; if (row != -1) { [list removeObjectAtIndex:row]; } [tableView reloadData]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:list]; [data writeToFile:filepath options:NSDataWritingAtomic error:nil]; } -(void)dealloc { [super dealloc]; } @end </code></pre> <p>hope this helps</p> <p>(xcode 4.2.1 for OS X)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload