2017-01-29 4 views
0

私は初心者です。なぜ私のCollectionViewControllerがDetailViewControllerのプロパティを表示していないのか理解しようとしています...ヒントや洞察力があれば幸いです。私のdetailViewController.hと私のCollectionViewController.mには、それぞれ以下のコードがあります。CollectionViewController DetailViewControllerのプロパティが表示されない

// DetailViewController.h 
// RecipePhoto 
// 


#import <UIKit/UIKit.h> 

@interface DetailViewController : UIViewController 

@property (weak, nonatomic) IBOutlet UIImageView *recipeImageView; 
@property (nonatomic) NSString *recipeImageName; 
- (IBAction)close:(id)sender; 

@end 


#import "RecipeCollectionViewController.h" 
#import "DetailViewController.h". 

@interface RecipeCollectionViewController() <UICollectionViewDataSource, UICollectionViewDelegate> 
{ 
    NSArray *recipeImages; 
} 
@end 

@implementation RecipeCollectionViewController 

static NSString * const reuseIdentifier = @"Cell"; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    recipeImages = [NSArray arrayWithObjects:@"angry_birds_cake.jpg", @"creme_brelee.jpg", @"egg_benedict.jpg", @"full_breakfast.jpg", @"green_tea.jpg", @"ham_and_cheese_panini.jpg", @"ham_and_egg_sandwich.jpg", @"hamburger.jpg", @"instant_noodle_with_egg.jpg", @"japanese_noodle_with_pork.jpg", @"mushroom_risotto.jpg", @"noodle_with_bbq_pork.jpg", @"starbucks_coffee.jpg", @"thai_shrimp_cake.jpg", @"vegetable_curry.jpg", @"white_chocolate_donut.jpg", nil]; 
    } 


// In a storyboard-based application, you will often want to do a little preparation before navigation 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

if ([segue.identifier isEqualToString:@"showRecipePhoto"]) { 
NSArray *indexPaths = [self.collectionView indexPathsForSelectedItems]; 

     // Get the new view controller using [segue destinationViewController]. 

    DetailViewController *detailViewController = [segue destinationViewController]; 
NSIndexPath *indexPath = [indexPaths objectAtIndex:0]; 

    // Pass the selected object to the new view controller. 
    DetailViewController.recipeImageName = [recipeImages[indexPath.section] objectAtIndex:indexPath.row]; 
[self.collectionView deselectItemAtIndexPath:indexPath animated:NO]; 
} 
} 

#pragma mark <UICollectionViewDataSource> 

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 
    //return arrayName.count; 
    return 1; 
} 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
    return recipeImages.count; 
} 
//provides the data for the collection view cells 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 

    // Configure the cell 
    UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100]; 
    recipeImageView.image = [UIImage imageNamed:[recipeImages objectAtIndex:indexPath.row]]; 

    return cell; 
} 
+0

ようこそスタックオーバーフロー!デバッグの助けを求める質問( "なぜこのコードは動作しないのですか?")には、目的の動作、_a特定の問題またはerror_を含める必要があります。明確な問題文がない質問は、他の読者にとって有用ではありません。参照:[最小限で完全で検証可能なサンプルの作成方法](http://stackoverflow.com/help/mcve) –

答えて

1

あなたはprepareForSegueのクラスプロパティとしてrecipeImageNameを使用しようとしている。

DetailViewController.recipeImageName = [recipeImages[indexPath.section] objectAtIndex:indexPath.row]; 

detailViewController.recipeImageName = [recipeImages[indexPath.section] objectAtIndex:indexPath.row]; 

する必要がありますが、最初の文字の大文字小文字に細心の注意を払ってください。 DetailViewControllerはクラスです。 detailViewControllerはローカル変数です。

+0

はい、ありがとうございました。 :) – Susanglin

+0

@AngieLinton、正解が入力された場合は、答えの左上にある小さな緑色のチェックボックスをオンにして、正解にするのが適切です。サイトがうれしかったのはうれしいですが、丁寧に使ってください。 (ジョーCは、問題があなたの部分でデバッグの証拠を提供していないことも正しい) – danh

+0

@danh教えていただきありがとうございます。それが私の最初の質問でした。私はそのステップを逃したことに気付きませんでした。乾杯! – Susanglin

関連する問題