我想将NSString数据存储在NSMutableDictionary中

时间:2014-11-15 10:25:08

标签: ios objective-c nsstring nsmutabledictionary

我正在尝试将数据存储在NSMutableDictionary中。继续更改NSString值我想将此值存储在NSMutableDictionary中,但是当NSMutableDictionary中的第二次存储值然后清除旧值时,如何在{{1}中逐个存储值}。

NSMutableDictionary

继续更改所有标签值我希望将这些值存储在 NSString *tempitemname = itemselectedlbl.text; NSString *temprate = ratelbl.text; NSString *tempquant = quantitylbl.text; NSString *temptotal = totallbl.text; NSString *temptotalbill = totalbilllbl.text; dict = [[NSMutableDictionary alloc]init]; [dict setValue:tempitemname forKey:@"itemname"]; [dict setValue:temprate forKey:@"rate"]; [dict setValue:tempquant forKey:@"quantity"]; [dict setValue:temptotal forKey:@"total"]; [dict setValue:temptotalbill forKey:@"totalbill"];

1 个答案:

答案 0 :(得分:0)

NSDictionary / NSMutableDictionary不允许在其中存储重复键。因此,当您第二次设置值时,如果字典中已存在可用键,则会覆盖数据。所以你不能一次又一次地存储,仍然期望它能保存所有数据。