Susanglin
Susanglin

Reputation: 3

CollectionViewController not seeing properties on the DetailViewController

I'm a novice and I'm trying to understand why my CollectionViewController is not seeing properties on the DetailViewController...any tips or insight would be appreciated. Code below...for my detailViewController.h and also my CollectionViewController.m, respectively.

//  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;
}

Upvotes: 0

Views: 41

Answers (1)

nils
nils

Reputation: 1976

You are trying to use recipeImageName as a class property in prepareForSegue:

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

should be

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

Pay close attention to the capitalisation of the first letter. DetailViewController is the class; detailViewController is the local variable.

Upvotes: 1

Related Questions