我有NSMutableDictionary
并且我正在尝试向该字典添加值,我从另一个页面发送了一个值。
当我在if块打印之外打印它时,但当if块中有NSLog
时,值为null
。
我试过这样的话:
self.qr1=[NSString stringWithFormat:@"%@",self.tablenu];
NSLog(@"qr code from scanner==%@",self.qr1);
self.title = @"Review Order";
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
self.custid =[defaults objectForKey:@"uid"];
self.phone=[defaults objectForKey:@"phnum"];
self.custname=[defaults objectForKey:@"custname"];
self.ordidsec=[defaults objectForKey:@"orderid"];
self.qrcodesec=[defaults objectForKey:@"qrcode"];
NSLog(@"defaults---%@ %@ %@ ",self.custname,self.custid,self.phone);
self.order_cart = [[[NSUserDefaults standardUserDefaults] objectForKey:@"Order"] mutableCopy];
if (!_order_cart) {
self.order_cart = [[NSMutableArray alloc] init];
}
NSLog(@"qrrr %@",self.qr1);//this gives the value
if(_lname != NULL). //This is the block.
{
_tvar[@"item_name"] = _lname;
_tvar[@"item_quantity"] = _quan;
_tvar[@"price"] = _price;
_tvar[@"item_id"]=_idpro;
_tvar[@"phone"]=_phone;
_tvar[@"qr_code"]=[NSString stringWithFormat:@"%@" ,self.qr1];
_tvar[@"_id"]=_id4;
_tvar[@"customer_name"]=_custname;
_tvar[@"customer_id"]=_custid;
NSLog(@"qrrr indise %@",self.qr1);//this gives null
NSLog(@"order caertttt=== %@",_tvar);
[_order_cart addObject:_tvar];
[[NSUserDefaults standardUserDefaults] setObject:_order_cart forKey:@"Order"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"qr 4555 added %@ --- %@",_cus33tname,[_tvar valueForKey:@"dd"]);
NSLog(@"qr added %@ --- %@",_qr1,[_tvar valueForKey:@"qr_code"]);
}
目标: - 我想在该词典中添加值
Def: -
@property (strong,nonatomic) NSString *qr1;
@property (strong, nonatomic) NSMutableDictionary *tvar;