0

私は配列のディクショナリを持っており、これらの配列にはそれぞれ多数の配列があります。辞書内の多次元配列です。

UItable 行をクリックすると、ビューが別のクラスにプッシュされますが、オブジェクト キーがクリックされた行名と同じ配列であるビューと共にプッシュしたいと考えています。

私のコードは次のとおりです(プッシュを行うクラス)

- (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];

}

(ビューがプッシュされるクラス)

- (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;
}

ご覧のとおり、私は自分でさまざまな方法を試したため、多くのコメントがあります。

4

0 に答える 0