最喜欢的功能崩溃

时间:2014-03-24 00:29:59

标签: ios objective-c uitableview parse-platform favorite

我正致力于实施"收藏"我的应用中的功能。

这个想法是"最喜欢的"一页快速回到它。

以下是我的尝试:

// In the Detail View Controller
- (void)favoriteRecipe
{
    NSUserDefaults * prefs = [NSUserDefaults standardUserDefaults];
    NSMutableArray * favoriteDrinks;

    if ([prefs objectForKey:@"favoriteDrink"] == nil)
    {
        NSMutableArray * array = [[NSMutableArray alloc] init];
        [prefs setObject:array forKey:@"favoriteDrink"];
    }
    NSMutableArray * tempArray = [[prefs objectForKey:@"favoriteDrink"] mutableCopy];
    favoriteDrinks = tempArray;

    NSString * drinkNameString = self.drinkNameLabel.text;
    NSString * ingredientString = self.ingredientLabel.text;
    NSArray * favArray = [NSArray arrayWithObjects:drinkNameString, ingredientString, nil];
    [favoriteDrinks addObject:favArray];
    isFavorite = YES;
    [prefs setObject:favoriteDrinks forKey:@"favoriteDrink"];

    if (isFavorite == YES)
    {
        //Change the image 
    }
}

在我的FavoriteViewController中,我设置了一个表。我希望显示名称,然后选择它将转到该页面。

我使用Parse.com作为我的后端,所以我只有一个细节视图控制器根据项目进行更改。

这里我尝试返回详细视图控制器但崩溃:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    RecipeDetailViewController * recipeDetail = [[RecipeDetailViewController alloc] initWithNibName:@"RecipeDetailViewController" bundle:nil];

    PFObject * favObjects = [self.favArray objectAtIndex:indexPath.row];

    NSArray * ingredients = [favObjects objectForKey:@"ingredients"]; //Crashes Here

    recipeDetail.ingredientArray = ingredients;

    NSString * nameString = [favObjects objectForKey:@"recipe_name"];
    recipeDetail.nameString = nameString;

    [self.navigationController pushViewController:recipeDetail animated:YES];
}

我收到的错误是:

-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0xe76bea0

任何建议都将不胜感激!

1 个答案:

答案 0 :(得分:0)

此错误意味着您尝试在阵列上调用objectForKey。看来你通过致电[self.favArray objectAtIndex:indexPath.row]获得的回报并不是你期望得到的。你期待一个PFObject,但似乎你得到一个数组(如果确实是导致崩溃的那条线)。

查看调试器,了解[self.favArray objectAtIndex:indexPath.row]实际返回的内容。

相关问题