0

次のような 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];
    }
}

上記の 3 行目 (「if」) で、「arrReceipes」に「main」メソッドで例外をスローする場合。

私の問題を理解してください.助けてください.ありがとう.

4

3 に答える 3

1

入れているオブジェクトarrReceipesは辞書であるため、destViewController.recipeNameこれらのオブジェクトの 1 つを渡したい場合は、辞書である必要があります。

于 2012-12-05T15:00:59.013 に答える
0

あなたはで試すことができます

NSArray *somevariable = [NSArray arrayWithArray:arrReceipes];

NSMutableArrayはNSArrayのサブクラスであるため、NSArrayメソッドを使用できます。

于 2012-12-05T18:11:36.473 に答える
0

NSArray に書き込むことはできません。

ただし、次のようなことができます。

NSArray * somevariable = [arrReceipes copy];

また、コードを変更してデータを NSMutableArray に書き込み、それを次の場所にコピーすることもできます。arrRecipes

于 2012-12-05T15:01:41.243 に答える