0

我正在将购买的商品添加到数组中,这样我就可以轻松地检索数据并在表格视图中显示它们。但是我收到 sigabrt 错误。下面的代码有什么问题?

表视图

if (indexPath.section == 0) {

    switch (indexPath.row) {
        case 0:

            cell.textLabel.text = @"Default Gun";
            break;

        case 1:

            cell.textLabel.text = [[[[GameData sharedData] gunsArray] objectAtIndex:0] localizedTitle];
            break;


        default:
            break;

    }


    - (NSMutableArray *) gunsArray {

        SKProduct *product1 = [[InAppStore sharedStore] getGun1];
        SKProduct *product2 = [[InAppStore sharedStore] getGun2];
        SKProduct *product3 = [[InAppStore sharedStore] getGun3];
        SKProduct *product4 = [[IInAppStore sharedStore] getGun4];

        NSMutableArray *arr = [[NSMutableArray alloc] init];

        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isGun1Purchased"] == YES && ![arr containsObject:product1]) {
            [arr addObject:product1];  // error occurs here

        }
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isGun2Purchased"] == YES && ![arr containsObject:product2]) {
            [arr addObject:product2];  

        }
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isGun3Purchased"] == YES && ![arr containsObject:product3]) {
            [arr addObject:product3];

        }

        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isGun4Purchased"] == YES && ![arr containsObject:product4]) {
            [arr addObject:product4];

        }

        return [arr autorelease];
    }
4

1 回答 1

1

您可能尝试插入nil到数组中(这将导致异常并最终插入 SIGABRT)。因此,检查product变量之一是否为nil.

哦,您应该切换到 ARC(尽管这与您的问题无关)。

于 2013-03-05T11:50:20.377 回答