KVO和NSMutableArray [英] KVO and NSMutableArray

查看:145
本文介绍了KVO和NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置KVO与 NSMutableArray

数组。

推荐答案

我想你会对此问题。关键是你不能直接观察数组上的任何属性 - 数组只是存储 - 但你可以观察该数组支持的一对多关系(这里我假设你的数组是某个对象上的属性)。如果你不想在这些地方使用这些特殊的访问器,你拥有数组的代码可以调用 -willChange:valuesAtIndexes:forKey: -didChange:valuesAtIndexes:forKey:,如此答案。如果你是在Mac而不是iOS,你应该考虑 NSArrayController

I think you'll be interested in the answers to this question. The key is that you can't observe any properties on the array directly—the array is just storage—but you can observe the to-many relationship that's backed by that array (here I'm assuming your array is a property on an object somewhere). If you don't want to use those special accessors all over the place, your code that owns the array can call -willChange:valuesAtIndexes:forKey: and -didChange:valuesAtIndexes:forKey: as described in this answer. And if you're on a Mac and not iOS, you should consider NSArrayController.

这篇关于KVO和NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆