CollectionViewController is blank

82 Views Asked by At

There are no errors in the code that pop up and when the app loads in the simulator, it is completely blank. I think it might be a problem with the PList data not populating into the Arrays correctly but I am not sure as even the header/footer is not showing up.

Here is an example of one of the Plists (There are 4 total plists, all with the same structure, just being assigned to different objects):

Here is the code for one of the objects being assigned to an array and then pieces of those arrays being put into separate arrays to keep track of their thumbnails and names for the labels:

//BEGIN INGREDIENT ITEM DATA
    NSString *ingredientItemsPath = [[NSBundle mainBundle] pathForResource:@"IngredientList" ofType:@"plist"];
    NSMutableArray *ingredientItemsArray = [[NSMutableArray alloc] initWithContentsOfFile:ingredientItemsPath];
    /*NSString *ingredientItemsPath = [[NSBundle mainBundle] pathForResource:@"ingredientList" ofType:@"plist"];
    NSDictionary *ingredientItemsDict = [[NSDictionary alloc] initWithContentsOfFile:ingredientItemsPath];
    NSArray *ingredientItemsArray = [NSArray arrayWithArray:[ingredientItemsDict objectForKey:@"Root"]];*/
    NSMutableArray *cCalcIngredientObjects = [[NSMutableArray alloc] init];
    for (int index=0; index < ingredientItemsArray.count; index++)
    {
        CCalcIngredients* ingredient = [[CCalcIngredients alloc] init]; // This is your object
        NSDictionary* ingredientDict = (NSDictionary*)ingredientItemsArray[index];
        ingredient.name = ingredientDict[@"name"];
        ingredient.thumbnail = ingredientDict[@"thumbnail"];
        NSDictionary* ingredientNutritionDict = (NSDictionary*)ingredientDict[@"nutrition"];
        ingredient.calories = ingredientNutritionDict[@"calories"];
        ingredient.totalFat = ingredientNutritionDict[@"totalFat"];
        ingredient.saturatedFat = ingredientNutritionDict[@"saturatedFat"];
        ingredient.transFat = ingredientNutritionDict[@"transFat"];
        ingredient.cholesterol = ingredientNutritionDict[@"cholesterol"];
        ingredient.sodium = ingredientNutritionDict[@"sodium"];
        ingredient.totalCarbs = ingredientNutritionDict[@"totalCarbs"];
        ingredient.dietaryFiber = ingredientNutritionDict[@"dietaryFiber"];
        ingredient.proteins = ingredientNutritionDict[@"proteins"];
        [cCalcIngredientObjects addObject:ingredient];
    }
    //END INGREDIENT ITEM DATA

    NSLog(@"The ingredient items are %@", cCalcIngredientObjects);

    //array of photos
    self.photos = [[NSMutableArray alloc] init];
    for(CCalcMeals* item in cCalcMenuObjects){
        [self.photos addObject:item.thumbnail];
    }
    for(CCalcMeat* meat in cCalcMeatObjects){
        [self.photos addObject:meat.thumbnail];
    }
    for(CCalcSalsa* salsa in cCalcSalsaObjects){
        [self.photos addObject:salsa.thumbnail];
    }
    for(CCalcIngredients* ingredient in cCalcIngredientObjects){
        [self.photos addObject:ingredient.thumbnail];
    }
    NSLog(@"photos %@", self.photos);

NSLog prints this when I've ran it against all of the arrays that I have created:

I am trying to figure out why this is building to just a blank black simulator screen and to figure out what is going on with my Plist data and whether or not it is being built correctly.

1

There are 1 best solutions below

0
On

Upon messing around with the code I found that I was trying to pull out the information from the Plist as an Array even though the root information is in fact a Dictionary so now I know exactly why the NSLog's I had were only returning Nil. Thanks for the help and tips!