ios - 如何更新 NSMutableDictionary 中的 NSMutableArray 值

标签 ios objective-c xcode nsmutablearray nsmutabledictionary

我有一个 NSMutableDictionary Test = {key1:[0,0,0,0],key2:[0,0,8,0,0]}..这里的数组是 NSMutableArray。我需要更新一些值字典内的数组。例如。

- (IBAction)update(id)sender {
      UIButton *button = (UIButton *)sender;
      int test = 9;
      UIView *contentView = button.superview;
      UIView *viewWithTag16 = [contentView viewWithTag:16];
      NSIndexPath *indexPath = [self.dataColletionview indexPathForCell: (DataColletionViewCell *)[[sender superview]superview]];
      NSLog(@"flag values...%@",_flag);
      ...................... 
      .....................
     }

这里 indexpath.row 将是一个可变整数,标志将像 key1,key2,key3 类似于字典中的键。基于整数 a 值和 _flag 值,我需要更新字典中的数组值。示例_flag = key2 和 indaexpath.row = 3。我需要将测试整数值更新到第二个数组(key2)的第 3 个位置。

最佳答案

使用以下方式从字典中获取数组:

NSMutableArray *arr = [yourDict ObjectForKey:@"key2"];

通过以下方式替换数组中的对象:

[arr replaceObjectAtIndex:indexPath.row withObject:newObject];

如果你想把它放回去,

[yourDict setObject:arr forKey:@"key2"];

关于ios - 如何更新 NSMutableDictionary 中的 NSMutableArray 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24134321/

相关文章:

iOS AdMob 奖励视频

ios - 如何解冻 Xcode 模拟位置?

iphone - 获取节点 :withName: method of soap is called more than 2 million times when parsing some big xml web service

ios - 获取 interactivePopGestureRecognizer 关闭回调/事件

iphone - 如何在 iOS SDK 中为用户准备一条短信

ios - 在 iOS 的 xcode 4.6.2 中编译 OpenCV 2.4.5

xcode - XCode中的星号“*”之间有什么区别?

iPhone - 无法在 iOS 5.0.1 设备上从 XCode 运行应用程序,因为 iOS 从 5.0 更新

jquery - backbone.js 路由器在 PhoneGap iOS 构建中失败

ios - 如何设置这种类型的底部边框文本框?