0
votes

Probably a really dumb question but I'm having some trouble. Essentially I'm trying to take a first name and last name from text fields in the storyboard and store both values into one index of an array to call back at another time. Here's what I have:

//File.h
@property NSString *firstName;
@property NSString *lastName;

- initWithFirstName: (NSString *) firstName lastName: (NSString *) lastName;

 

//File.m
-(id) initWithFirstName: (NSString *) firstName lastName: (NSString *) lastName{

self.firstName = firstName;
self.lastName = lastName;
return self;
}

 

//ViewController.h
@property File *name;
@property NSMutableArray *array;

 

//ViewController.m
[super viewDidLoad]
self.array = [[NSMutableArray alloc]init];
self.name = [[File alloc] initWithFirstName: self.firstNameText.text lastName: self.lastNameText.text];

//under the save button
[self.array addObject:self.name];

//under the restore button
self.firstNameText.text = self.array[..?

That part (..?) is where I screw up. I can't go self.array[0].firstName because it doesn't exist. If I put array without an index the same thing happens. I know I must be messing up somewhere, maybe the firstName and lastName aren't even getting stored into the array at all.
Any help is greatly appreciated :)

2

2 Answers

1
votes

//under the restore button

File *objFile=[self.array objectAtIndex:0];

self.firstNameText.text=objFile.firstName;
1
votes

You can get using

self.firstNameText.text = ((File*)self.array[0]).firstName;

or

self.firstNameText.text = [[self.array objectAtIndex:0] firstName];

Your firstName and lastName are stored as Object in array, so you need to typecast it into object back to get it working :)