I am going through the tutorials provided by Apple and tried to improve "My Second iOS App", the app for bird sightings. (There is a MasterView where all entered sightings are listed. If you click one, you are directed to a DetailView of the sighting. You can add a sighting and are asked to enter a name and location.)
I want to sepperate the views for entering the birds name and location.
So I have two views (one for entering the name and one for entering the location) and one object I want to store.
In the file BirdSighting.m
I added the following methods
-(id)initWithNameOnly:(NSString *)name date:(NSDate *)date
{
self = [super init];
if (self) {
_name = name;
_date = date;
return self;
}
return nil;
}
and
-(id)setLocation:(NSString *)location
{
if (self) {
_location = location;
return self;
}
return nil;
}
In the AddSightingNameViewController.m
I implemented the following code
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"ToLocation"])
{
if ([self.birdNameInput.text length])
{
BirdSighting *sighting;
NSDate *today = [NSDate date];
sighting = [[BirdSighting alloc] initWithNameOnly:self.birdNameInput.text date:today];
self.birdSighting = sighting;
}
}
}
The view for entering the name leads with a push segue to the location-view. There has'nt been changed much else.
Now how do I pass the object generated in the first view to the second? And how do I call the setLocation
method on this specific object in AddSightingLocationViewController.m
? Do I have to define different properties? And how do I finally display the object in the MasterView with the correct data after I entered the location?
As this code is not working yet, I don't even know if it is working, what I am trying to do. So please be gentle, if this is crappy code.