CollectionViewController是空白的

时间:2014-01-31 00:25:17

标签: ios objective-c arrays property-list

弹出的代码中没有错误,当应用程序在模拟器中加载时,它完全是空白的。我认为PList数据没有正确填充到数组中可能是一个问题,但我不确定即使页眉/页脚没有显示出来。

以下是其中一个Plists的示例(共有4个plist,所有结构都相同,只是分配给不同的对象):

以下是分配给数组的其中一个对象的代码,然后将这些数组的各个部分放入单独的数组中,以跟踪其标签的缩略图和名称:

//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会打印出来:

我试图弄清楚为什么这只是建立一个空白的黑色模拟器屏幕,并弄清楚我的Plist数据是什么以及它是否正确构建。

1 个答案:

答案 0 :(得分:0)

在搞乱代码时,我发现我试图将Plist中的信息作为数组提取出来,即使根信息实际上是一个字典,所以现在我确切地知道为什么我的NSLog只返回Nil 。 感谢您的帮助和提示!