Saturday, 7 September 2013

TableviewController as detail controller with NSmutable Arrays

TableviewController as detail controller with NSmutable Arrays

say you have Nsmutable array that gets its data through JSON. This data is
displayed on tableview controller which has another tableviewcontroller as
detail and another tableviewcontroller as a third detail.
I have declared properties and synthesised the arrays as follows table1
view controller
NSMutableArray *venueData;
NSMutableArray *patientData;
NSMutableArray *moreInfo
the second table will drilldown on venues and patient data
The table source receives its data via json as follows
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse
*response, id JSON) {
id results = [JSON valueForKeyPath:@"data"];
[results enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL
*stop) {
[self.venueData addObject:[NSString stringWithFormat:@"%@",[obj
valueForKey:@"venueInfo"]]];
[self.patientData addObject:[NSString stringWithFormat:@"%@",[obj
valueForKey:@"patientInfo"]]];
[self.moreData addObject:[NSString stringWithFormat:@"%@",[obj
valueForKey:@"moreInfo"]]];
//additional code etc
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//usual code, uiviewcell subclass, dequeueReusableCellWithIdentifier etc
[[cell venue] setText:[NSString stringWithFormat:@"%@", [venueData
objectAtIndex:indexPath.row]]];
[[cell patient] setText:[NSString stringWithFormat:@"%@", [patientData
objectAtIndex:indexPath.row]]];
return cell;
}
next
I am using segue
if ([segue.identifier isEqualToString:@"ShowDetails"])
{
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
SecondViewController *detailViewController =
segue.destinationViewController;
//detailViewController.delegate=self;
detailViewController.moreInfo=[NSString
stringWithFormat:@"%@",[moreData objectAtIndex:selectedRowIndex.row]];
}
I have created a third array and called it moreInfo, where I am storing
moreInfo such as venueDescription, venueLocation etc
such that in secondViewController, my row is returned by the content of
that array
I am able to receive data on first table, however the detail table
displays the same information for all the indexes e.g when you click VenuI
or Venue2, you get all the details for venue 1, venue 2, venue 3 etc
Could I get ideas on the best approach

No comments:

Post a Comment