0

I have a dictionary of arrays, and each of these arrays has a number of arrays itself. Its a multidimensional array in a dictionary.

When I click on a UItable row, I push the view to another class, however I want to push along with the view, the array whose object key is the same as the row name that was clicked.

My code is as follows (The class that does the pushing)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller

if(dvController == nil) 
dvController = [self.storyboard instantiateViewControllerWithIdentifier:@"FoodCategoryView"];



//NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//NSMutableDictionary *keysAndObjects = [defaults objectForKey:@"keysAndObjects"];

Food *foodObj;

/*for (id key in [keysAndObjects allKeys]) {
    NSArray *foodArray = [keysAndObjects objectForKey:key];        
     foodObj = [foodArray objectAtIndex:indexPath.row];    
}*/

/*for (id key in [keysAndObjects allKeys]) {
    NSArray *foodArray = [keysAndObjects objectForKey:key];  
    for (Food *food in foodArray) {
        // do stuff with Food object
        //NSLog(@"%@", food.foodName);
    }
}*/


NSMutableArray *objects2   = [[NSMutableArray alloc] init];
NSMutableArray *objects1   = [[NSMutableArray alloc] init];
objects1 = [objects objectAtIndex:indexPath.row];  
objects2 = [objects1 objectAtIndex:indexPath.row];   
foodObj = objects2;

//NSLog(@"Object %@", [objects objectAtIndex:indexPath.row]);
NSLog(@"foodObj %@", foodObj);




//Get the detail view data if it does not exists.
//We only load the data we initially want and keep on loading as we need.
//[foodObj hydrateDetailViewData];

dvController.foodObj = foodObj;

[self.navigationController pushViewController:dvController animated:YES];

}

(the class that the view is pushed to)

- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}

/*for (Food *food in foodObj) {
    // do stuff with Food object
    NSLog(@"%@", food.foodName);
    cell.text = food.foodName;
}*/

//Food *food = [foodObj objectAtIndex:indexPath.row];
//cell.text = [foodObj objectAtIndex:indexPath.row];
cell.text = foodObj.foodName;
NSLog(@"%@", foodObj.foodName);

return cell;
}

As you can see there are lots of comments as I have tried lots of different ways to do it myself.

4

0 回答 0