【发布时间】:2016-10-12 15:50:49
【问题描述】:
我有一个带有特定 key 和 value 的 NSMutableDictionary。该字典位于 NSMutableArray 中。我想用数组内某个索引处的特定键更新字典。我想找到这个字典对象的索引。目前,我的字典在索引 0 处,而我的 editingIndexPath 是 1,属于 NSIndexPath 类型,所以 editingIndexPath.row 对我没有帮助。
我的代码如下:
//UpdatedDateAndTime is the NSMutableArray.
//selectedDay is a NSString object.
//dateKeySelected is also a string key.
[[updatedDateAndTime objectAtIndex:editingIndexPath.row] setObject:selectedDay forKey:dateKeySelected];
我的问题是我想获得找到的字典的正确索引。
【问题讨论】:
-
上述代码有什么问题?它设置了密钥吗?字典的索引不是和editingIndexPath.row一样吗?
-
@TejaNandamuri...不!如果字典已经存在于数组中怎么办。对我来说,它位于
index,值为0,而在表格视图中,我对应于该字典的单元格是editingIndexPath.row,即1。我想要字典对应的数组索引。 -
你怎么知道这是索引 1 的那个?您如何比较字典?
-
@Larme..我的评论可能会给你答案。
-
@Ron NSMutableArray 是否包含不同的类或所有 NSMutableDictionary?
标签: ios objective-c nsmutablearray nsmutabledictionary