我想在我的表中添加一列。此列已添加到 SAP 系统的后端数据库中。当首次连接到 SAP 系统时,我还可以看到该值已填充到数据提取中。成功登录后,它运行材料提取功能模块并返回一列“价格”,我需要将其添加到我在 xcode 中的应用程序中。
请帮我。
错误:“以 NSException 类型的未捕获异常终止”由于未捕获异常“NSInvalidArgumentException”而终止应用程序,原因:“ * setObjectForKey:对象不能为 nil(键:itemPrice)”第一次抛出调用堆栈:
if(!found){
NSMutableDictionary *mDic = [[NSMutableDictionary alloc] init];
[mDic setObject:[dic valueForKey:@"itemId"] forKey:@"itemId"];
[mDic setObject:[dic valueForKey:@"itemR"] forKey:@"itemR"];
[mDic setObject:[dic valueForKey:@"itemQty"] forKey:@"itemQty"];
[mDic setObject:[dic valueForKey:@"itemDesc"] forKey:@"itemDesc"];
[mDic setObject:[dic valueForKey:@"itemPack"] forKey:@"itemPack"];
[mDic setObject:[dic valueForKey:@"itemUOM"] forKey:@"itemUOM"];
[mDic setObject:[dic valueForKey:@"itemNACS"] forKey:@"itemNACS"];
[mDic setObject:[dic valueForKey:@"itemPrice"] forKey:@"itemPrice"]; // This is where the error is occuring.
int qty = [[dic valueForKey:@"itemQty"] intValue];
// float price = [[dic valueForKey:@"itemPrice"] floatValue];
// price = price * qty;
// [mDic setObject:[NSString stringWithFormat:@"%.2f", price] forKey:@"itemPrice"];
mQty = qty;
[mDic setObject:[dic valueForKey:@"itemLastSold"] forKey:@"itemLastSold"];
[items addObject:mDic];
[mDic release];
}
Its actually not being retrieved from dic dictionary variable.
This is the code for adding that itemPrice to the table
int mQty;
//DELETE AND RE-ADD
for (int i=0; i<[items count]; i++) {
if([[dic valueForKey:@"itemId"] isEqualToString:[[items objectAtIndex:i] valueForKey:@"itemId"]]){
NSLog(@"qty %@",[dic valueForKey:@"itemQty"]);
int qty = [[dic valueForKey:@"itemQty"] intValue];
qty = qty + [[[items objectAtIndex:i] valueForKey:@"itemQty"] intValue];
NSDictionary *d = [items objectAtIndex:i];
NSLog([d description]);
[[items objectAtIndex:i] setValue:[NSString stringWithFormat:@"%d", qty] forKey:@"itemQty"];
found = YES;
[items removeObjectAtIndex:i];
NSMutableDictionary *mDic = [[NSMutableDictionary alloc] init];
[mDic setObject:[dic valueForKey:@"itemId"] forKey:@"itemId"];
[mDic setObject:[dic valueForKey:@"itemR"] forKey:@"itemR"];
[mDic setObject:[NSString stringWithFormat:@"%d", qty] forKey:@"itemQty"];
[mDic setObject:[dic valueForKey:@"itemDesc"] forKey:@"itemDesc"];
[mDic setObject:[dic valueForKey:@"itemPack"] forKey:@"itemPack"];
[mDic setObject:[dic valueForKey:@"itemUOM"] forKey:@"itemUOM"];
[mDic setObject:[dic valueForKey:@"itemNACS"] forKey:@"itemNACS"];
[mDic setObject:[dic valueForKey:@"itemPrice"] forKey:@"itemPrice"]; //added price column
mQty = qty;
[mDic setObject:[dic valueForKey:@"itemLastSold"] forKey:@"itemLastSold"];
// [items insertObject:mDic atIndex:0];
[items addObject:mDic];
[mDic release];
break;
}