NSIndexSet* set = [NSIndexSet indexSetWithIndex:[someIndex integerValue]]; [self willChange:NSkeyvalueChangeInsertion valuesAtIndexes:set forKey:@"theArrayname"]; // add the objects at the specifIEd indexes here [self dIDChange:NSkeyvalueChangeInsertion valuesAtIndexes:set forKey:@"theArrayname"];
注册观察后,您将获得一个更改字典,其中包含已更改的索引.
但是,我不明白如何观察NSMutableDictionary的新对象添加.有没有办法观察对象的添加/删除?
谢谢,
[编辑]
我找到了满足当前需求的解决方案.我希望以下内容有助于未来的开发人员.
[self willChangeValueForKey:@"someDictionary" withSetMutation:NSkeyvalueUnionSetMutation usingObjects:[NSSet setWithObject:someObject]];[Images setobject:someObject forKey:someIndex];[self dIDChangeValueForKey:@"someDictionary" withSetMutation:NSkeyvalueUnionSetMutation usingObjects:[NSSet setWithObject:someObject]];解决方法 只是为了确保回答问题.信用转到@DoubleDunk
[self willChangeValueForKey:@"someDictionary" withSetMutation:NSkeyvalueUnionSetMutation usingObjects:[NSSet setWithObject:someObject]]; [Images setobject:someObject forKey:someIndex]; [self dIDChangeValueForKey:@"someDictionary" withSetMutation:NSkeyvalueUnionSetMutation usingObjects:[NSSet setWithObject:someObject]];总结
以上是内存溢出为你收集整理的ios – NSMutableDictionary添加和删除KVO全部内容,希望文章能够帮你解决ios – NSMutableDictionary添加和删除KVO所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)