ios - replaceObjectAtIndex objectforKey 崩溃

标签 ios iphone objective-c ipad nsmutablearray

我想用其他值替换数组的内容,

这是我的数组值:

    [Arr objectAtIndex:i] =  "End_Date" = "31 Mar 2014";
                             "Merchant_Category_Id" = 162;
                             "Merchant_ID" = 1262;
                             "Merchant_Name" = Mp;
                             "Merchant_SmallImage" = "http://abcdm/imge/cb256.jpg";
                             "Voucher_Id" = 130510;
                             "Voucher_Name" = "Rs 555 OFF";
                              favStatus = 0;

我想做的是,我想将索引 i 处的 favStatus 从 0 更新为 1

这是我试过的代码片段,

[Arr replaceObjectAtIndex:[[[Arr objectAtIndex:i] objectForKey:@"favStatus"] integerValue] withObject:@"1"];

每次它返回值 0 当我记录 [[[Arr objectAtIndex:i] objectForKey:@"favStatus"] integerValue]

请帮助并提前致谢。

最佳答案

您正在用字符串 @"0"替换整个对象(字典)。

事实上你可以创建一个新的tempDictionary,并提取@"favStatus"的keyValue。替换它,然后将新对象放入数组中:

NSMutableDictionary *tempDictionary = [[Arr objectAtIndex:i] mutableCopy];
[tempDictionary setValue:@"0" forKey:@"favStatus"];

 [Arr replaceObjectAtIndex: i
                withObject: tempDictionary];

关于ios - replaceObjectAtIndex objectforKey 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22472608/

相关文章:

ios - View Controller 如何展示自己?

iphone - 防止其他程序员调用 -init 的最佳方法

iphone - AVErrorInvalidVideoComposition = -11841

iOS 11 列出所有应用程序

ios - RxSwift - 使用两个可观察对象进行异步调用

iphone - 多按钮、多 View 的相同 UIalertview

iphone - 在 iPad 上收到内存警告

iphone - Objective-C : PackageApplication Failed during validation

iPhone 3.1 SDK : UIViewController category is affecting ALL ViewControllers

objective-c - C 或 ObjC 用于 iOS 上的实时光线追踪器?