[英]Passing NSMutableArray dictionary data to another view using segue
I have code like this: In .m
我有这样的代码:在
.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];
}
Now, I want to pass values from "arrReceipes"(in which I'm doing " addObject:dictionaryObject
") to another view controller using segue(or any other way, if you know) 现在,我想使用segue(或任何其他方式,如果您知道)将值从“ arrReceipes”(我正在执行“
addObject:dictionaryObject
”)传递给另一个视图控制器
And using "segue" I'm doing it using following: 使用“ 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];
}
}
I'm getting exception as my "arrReceipes" is NSMutableArray
assigned with dictionary objects.Instade if taking " NSMutableArray
", if I'm using " NSArray
" its working fine. 我收到异常,因为我的“ arrReceipes”是分配了字典对象的
NSMutableArray
。如果使用“ NSMutableArray
”,则说明安装正确,如果使用“ NSArray
”,则应进行说明。 But I want to use " NSMutableArray
"; 但是我想使用“
NSMutableArray
”; because with this I can make group in table view. 因为这样我可以在表视图中进行分组。
Probably you wanted 可能你想要
-(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];
}
Which is the same as 与...相同
destViewController.recipeName = [[[arrReceipes objectAtIndex:indexPath.section] valueForKey:@"Find Recipes"] objectAtIndex:indexPath.row];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.