我有NSMutableArray如下所示:
在.h中
@property (nonatomic,retain) NSMutableArray *arrReceipes;
在.m中
@synthesize arrReceipe;
方法内部
arrReceipes = [[NSMutableArray alloc] init];
NSArray *arrReceipesTime1;
NSArray *arrReciepHeart;
NSArray *arrRecipeLifestyle;
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",@"Outdoor cooking", nil];
NSDictionary *arrRecipeLifestyleDict = [NSDictionary dictionaryWithObject:arrRecipeLifestyle forKey:@"Find Recipes"];
[arrReceipes addObject:arrReceipeTime1Dict];
[arrReceipes addObject:arrRecipesHeartDict];
[arrReceipes addObject:arrRecipeLifestyleDict];
那就是“ arrReceipes”是我的NSMutable数组。
现在,我想提取“ arrReceipes”的值/字符串并将其放入“ NSArray * somevariable”。
我怎样才能做到这一点?
我正在为此:
-(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];
}
}
在上面的第三行中(如果是),如果我在“ main”方法中给“ arrReceipes”它的抛出异常。但是,如果我打算给“ arrReceipes”,那么我会给“ somevariable”它的工作罚款。
希望你理解我的问题。请帮忙。谢谢。
最佳答案
您要放入arrReceipes
的对象是字典,因此如果要将destViewController.recipeName
传递给这些对象之一,则它应该是字典。
关于iphone - 如何从NSMutablearray提取值并将其放入NSArray?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13725964/