0

我有这样的代码:在.m

    - (void)viewDidLoad
            {
            [super viewDidLoad];

        arrReceipes = [[NSMutableArray alloc] init];
        arrReceipesTime1 = [NSArray arrayWithObjects:@"Half an hour or less",@"About an hour",@"More than an hour", nil];
        NSDictionary *arrReceipeTime1Dict = [NSDictionary dictionaryWithObject:arrReceipesTime1 forKey:@"Find Recipes"];
        arrReciepHeart = [NSArray arrayWithObjects:@"HealthyAndDelicius", nil];
        NSDictionary *arrRecipesHeartDict = [NSDictionary dictionaryWithObject:arrReciepHeart forKey:@"Find Recipes"];
        arrRecipeLifestyle = [NSArray arrayWithObjects:@"Recipe for fall",@"Quick and easy",@"Cooking for kids",@"Easy entertaining",@"American classics", nil];
        NSDictionary *arrRecipeLifestyleDict = [NSDictionary dictionaryWithObject:arrRecipeLifestyle forKey:@"Find Recipes"];

        [arrReceipes addObject:arrReceipeTime1Dict];
        [arrReceipes addObject:arrRecipesHeartDict];
        [arrReceipes addObject:arrRecipeLifestyleDict];
   }

现在,我想addObject:dictionaryObject使用 segue(或任何其他方式,如果你知道的话)将值从“arrReceipes”(我正在做“”)传递到另一个视图控制器

并使用“segue”我正在使用以下内容:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
    if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
        NSIndexPath *indexPath = [self.tableView1 indexPathForSelectedRow];
       RecipeDetailViewController *destViewController = segue.destinationViewController;

       destViewController.recipeName = [arrReceipes objectAtIndex:indexPath.row];


    }

    }

我遇到了异常,因为我的“arrReceipes”被NSMutableArray分配了字典对象。如果使用“ NSMutableArray”,则如果我使用“ NSArray”,则它工作正常。但我想用“ NSMutableArray”;因为有了这个我可以在表格视图中进行分组。

4

1 回答 1

1

可能你想要

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
        NSIndexPath *indexPath = [self.tableView1 indexPathForSelectedRow];
        RecipeDetailViewController *destViewController = segue.destinationViewController;

        destViewController.recipeName = arrReceipes[indexPath.section][@"Find Recipes"][indexPath.row];
}

这与

destViewController.recipeName = [[[arrReceipes objectAtIndex:indexPath.section] valueForKey:@"Find Recipes"] objectAtIndex:indexPath.row];
于 2012-12-06T19:05:07.097 回答