Firstly, sorry if the title is confusing, I'm not sure how else to word it. I'll explain my app briefly.
User is presented with a Login screen (very basic, no server-side stuff), in which they can log in to three different companies (Company A, Company B, and Company C)
in that specific order. Once the user has successfully logged on to Company A
, they are presented with a TableView
. The LoginViewController
(normal ViewController
) downloads a ListOfClinics.xml
file from Dropbox and parses it using NSXMLParser
, and passes the object to the ClinicsViewController
to displays a list of Clinic locations.
ListOFClinics.xml
example:
<Clinic>
<Location>
<Clinic_Location>Manchester</Clinic_Location>
</Location>
<Location>
<Clinic_Location>Liverpool</Clinic_Location>
</Location>
<Location>
<Clinic_Location>Birmingham</Clinic_Location>
</Location>
<Location>
<Clinic_Location>London</Clinic_Location>
</Location>
<Location>
<Clinic_Location>Leeds</Clinic_Location>
</Location>
</Clinic>
ClinicViewController
is a TableViewController
. While the table is being populated, the app downloads another file from Dropbox (Clients.xml
) and parses it ready to be used. The idea is that a user can tap on a TableView cell
containing a location, such as Manchester, and the newly parsed data from the Clients.xml
should get passed to the next view (ClientsViewController
) and show all clients registered to the Manchester clinic.
Clients.xml
example:
<Client>
<Clinic_Location>Manchester</Clinic_Location>
<Client_Forename>Frank</Client_Forename>
<Client_Surname>Wade</Client_Surname>
<Client_Address_Line_1>Law Lane</Client_Address_Line_1>
<Client_Address_Line_2>Money House</Client_Address_Line_2>
<Client_Address_Line_3>Didsbury</Client_Address_Line_3>
<Client_Address_Line_4>Manchester</Client_Address_Line_4>
<Client_Address_Line_5></Client_Address_Line_5>
<Client_Postcode>M20 2WS</Client_Postcode>
<Client_Tel>01615559090</Client_Tel>
<Appt_Time>15:30</Appt_Time>
<Appointment_Attended>Booked</Appointment_Attended>
<Passed_To_Medical>Complete Pass</Passed_To_Medical>
<Passed_To_Sol>no</Passed_To_Sol>
</Client>
<Client>
...
</Client>
As you can see, both .xml files have the Clinic_Location
element. I'm not too worried about error checking to make sure the data in these match up (the .xml files are exported via another system, so both should have the same locations). What I need to implement is that when someone taps on Manchester, the next TableView
is presented with a list of Clients who are registered to the Manchester Clinic.
Update
I have created a new NSObject
class, declaring all properties in ClientData.h and synthesising them in ClientData.m
.
ClientData.h
@interface ClientData : NSObject
@property (strong) NSString *clinicLocation;
@property (strong) NSString *foreName;
...
ClientData.m
@implementation ClientData
@synthesize clinicLocation;
@synthesize foreName;
...
Below is a snippet of my parser component, using KVC to store the parsed data.
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"Client"]) {
// save to data structure object with KVC
ClientData *clientData = [[ClientData alloc]init];
clientData.clinicLocation = clinicLocation
clientData.foreName = foreName;
...
// count number of clients
clientCount++;
[client setObject:clinicLocation forKey:@"Clinic_Location"];
[client setObject:foreName forKey:@"Client_Forename"];
...
[dataStart addObject:[client copy]];
}
}
If I log the NSObject
string with NSLog(@"Forename: %@", clientData.foreName);
, etc, the output is correct.
I am using a storyboard with segues to push the next view. Should I implement prepareForSegue
to pass the NSObject (ClientData)
or tableView didSelectRowAtIndexPath
? Here is what I have tried:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showClients"]) {
// clientData is declared on the destinationViewController
PCClientsViewController *pcClients = segue.destinationViewController;
pcClients.clientData = [[ClientData alloc]init];
pcClients.clientData.foreName = foreName;
}
}
This works, although only one foreName
value is getting passed through to the next TableView
. Does my NSObject
class only store one value each time I'm assigning something to it? In other words, If I parse 100 records with 100 foreName
attributes, are all 100 values persisted or only the last one?
I still don't know what test to do here and only pass relevant data to the next view (ie. if user taps on Manchester
, pass all Clients with a Clinic_Location
of Manchester
to the next view). Should I create a new NSObject
class to store the ListOfClinics.xml
data and test it against the CLinic_Location
value in my ClientData NSObject
?