2

コンソールで NSCache を使用すると iOS アプリ プロジェクトがクラッシュし続ける

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCache setObject:forKey:cost:]: attempt to insert nil value (key: productAllergyCache)'
*** First throw call stack:
(0x1c9a012 0x10d7e7e 0x1c6f7d9 0x1c6f613 0x4211 0xfd1c7 0xfd232 0xfd4da 0x1148e5 0x1149cb 0x114c76 0x114d71 0x11589b 0x115e93 0x115a88 0x2c59 0xcb285 0xcb4ed 0xad55b3 0x1c59376 0x1c58e06 0x1c40a82 0x1c3ff44 0x1c3fe1b 0x1bf47e3 0x1bf4668 0x1bffc 0x20bd 0x1fe5) libc++abi.dylib: terminate called throwing an exception (lldb)

私のコードは次のようになります:

- (void)viewDidLoad
{
    [super viewDidLoad];
     // Do any additional setup after loading the view.
    detailViewmySQL = [[NSCache alloc]init];

    [self.detailViewmySQL setObject:productName forKey:@"productNameCache"];
    [self.detailViewmySQL setObject:productDescription forKey:@"productDescriptionCache" cost:1];
    [self.detailViewmySQL setObject:productImage forKey:@"productImageCache"];
    [self.detailViewmySQL setObject:productAllergy forKey:@"productAllergyCache"];
    [self.detailViewmySQL setObject:productQuantity forKey:@"productQuantityCache"];
    [self.detailViewmySQL setObject:productPrice forKey:@"productPriceCache"];

    self.title = [self.detailViewmySQL objectForKey:@"productNameCache"];

    outProductName.text = [self.detailViewmySQL objectForKey:@"productNameCache"];

    outProductDescription.text = [self.detailViewmySQL objectForKey:@"productDescriptionCache"];
    outProductImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[self.detailViewmySQL objectForKey:@"productImageCache"]]]];
    outProductAllergy.text = [self.detailViewmySQL objectForKey:@"productAllergyCache"];
    outProductQuantity.text = [self.detailViewmySQL objectForKey:@"productQuantityCache"];
    outProductPrice.text = [self.detailViewmySQL objectForKey:@"productPriceCache"];
}

ここにデータを設定し、上記の実装ファイルに渡します

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Passing data to view controller
    detailedViewController *productinfo = [self.storyboard instantiateViewControllerWithIdentifier:@"bakeryDetails"];

    //Retrieve current user array
    foodProducts *currentProduct = [bakeryProductArray objectAtIndex:indexPath.row];

    //Pass data to variables of detailedviewcontroller
    productinfo.productName = currentProduct.productName;
    productinfo.productImage = currentProduct.productImgUrl;
    productinfo.productQuantity = currentProduct.productquantity;
    productinfo.productPrice = currentProduct.productPrice;
    productinfo.productAllergy = currentProduct.productAllergy;
    productinfo.productDescription = currentProduct.productDescription;

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

コストと setTotalCostLimit を設定しようとしましたが、それでもクラッシュします。

悪の

4

1 に答える 1

0

detailViewmySQL強いと宣言しましたか?

文字列の長さが > 0 であるかどうかを確認できます。true の場合、その値を設定します。これにより、クラッシュが防止されます。

于 2013-11-26T12:44:27.497 に答える