私はこのようなコードを持っています:.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
; これでテーブルビューでグループを作ることができるからです。