使用 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 但仍然崩溃,有人知道我做错了什么吗?
邪恶的