gpt4 book ai didi

ios - 简单查询 : How does one detect the addition of an item in a mutable array?

转载 作者:行者123 更新时间:2023-12-01 19:14:58 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:




9年前关闭。




Possible Duplicate:
KVO and NSMutableArray



正如标题所说,我需要能够检测到可变数组的变化。这样做的原因是,一旦用户添加了新位置,就会自动刷新我正在制作的应用程序的 map View 。

我想这就像询问数组是否等于数组的计数加一或数组的计数减一,但我不知道如何实现。

如果您在回答之前需要更多信息,请随时在评论中提问。

最佳答案

您可以为此使用 Key-Value Observing。更多详情请查看Introduction to Key-Value Observing Programming Guide .

Key-value observing provides a mechanism that allows objects to be notified of changes to specific properties of other objects. It is particularly useful for communication between model and controller layers in an application. (In OS X, the controller layer binding technology relies heavily on key-value observing.) A controller object typically observes properties of model objects, and a view object observes properties of model objects through a controller. In addition, however, a model object may observe other model objects (usually to determine when a dependent value changes) or even itself (again to determine when a dependent value changes).

You can observe properties including simple attributes, to-one relationships, and to-many relationships. Observers of to-many relationships are informed of the type of change made—as well as which objects are involved in the change.



查看 this blog关于如何使用它的 KVO。还有 check this tutorial.也检查这个问题, Key-Value-Observing a to-many relationship in Cocoa

关于ios - 简单查询 : How does one detect the addition of an item in a mutable array?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13921499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com