我有一个数组字典,每个数组本身都有许多数组。它是字典中的多维数组。
当我点击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;
}
你可以看到有很多评论,因为我已经尝试了很多不同的方法来自己做。