I have populated a NSArray with results of a query from MagicalRecord (a Core Data wrapper). I need to take those results and display them in custom cells in a UITableView from within cellForRowAtIndexPath:, but the index refers to another UITableView that has been selected.
I have two UITableViews; one contains a list of customers, the other contains a list of appointments for each customer. When the user selects a customer, the code finds all of the appointments for that customer. As such, there is no index involved with the second table view).
The first table view has a list of clients; when the user selects one of those clients, the second table view is populated with a list of appointments for that selected client. Thus the index.row refers to the first UITableView and the second has no index it can refer to. I just dump the contents of the apptDataArrray into the cells.
Here is my code:
if(tableView.tag == 2) { // appointment info
static NSString *cellIdentifier = @"apptListCell";
ApptCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[ApptCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
// configure the cell...
AppointmentInfo *currentAppointment = [apptDataArray objectAtIndex: 0]; // go through the array <---- TODO
// Set the dateFormatter format
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // start date/time
[timeFormatter setDateFormat:@"HH:mm:ss"]; // end time
UILabel *label = (UILabel *)[cell viewWithTag:3]; // display start date/time (NEEDS TO BE LOCALIZED!)<----- TODO????
label.text = [dateFormatter stringFromDate:currentAppointment.aStartTime];
label = (UILabel *)[cell viewWithTag:4]; // display end time
label.text = [timeFormatter stringFromDate:currentAppointment.aEndTime];
label = (UILabel *)[cell viewWithTag:5]; // display service tech name
label.text = currentAppointment.aServiceTech;
return cell;
}
My question is: When at the line below // configure the cell, how do I iterate through the apptDataArray each time cellForRowAtIndexPath: is called, since there is NO index that can be applied to this array?