我有这样的代码:
在.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的视图控制器(或任何其他方式,如果你知道的话)
使用“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
”;因为有了这个,我可以在表格视图中制作组。
答案 0 :(得分: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];