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

ここで、「arrReceipes」(「」を実行しているaddObject:dictionaryObject)からsegue(または知っている場合は他の方法)を使用して別のViewControllerに値を渡したいと思います。

そして「セグエ」を使って私は以下を使ってそれをやっています:

-(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 に答える