更改NSManagedObject属性而不触发委托方法? [英] Change NSManagedObject property without triggering delegate methods?

查看:117
本文介绍了更改NSManagedObject属性而不触发委托方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有任何方法(或技巧),我可以修改目前由委托 NSFetchedResultsController 持有的 NSManagedObject 触发 didChangeObject: controllerWillChangeContent:委托方法?

Is there any way (or tricks) where I can modify an NSManagedObject currently held by a delegated NSFetchedResultsController without triggering the didChangeObject: and controllerWillChangeContent: delegate methods?

例如,current如果我改变 myObject.property = @hello; ,触发委托方法并更新我的表视图,但我不希望这种情况发生,但只是对于明确指定的某些更改,而不是所有更改。

For example, current if I change myObject.property = @"hello";, the delegate methods are triggered and updates are made to my table view, but I don't want that to happen, but only for certain changes where I explicitly specify, not all changes.

推荐答案

中的 setPrimitiveValue:forKey: > NSManagedObject 正是这样,例如

The setPrimitiveValue:forKey: method from NSManagedObject does exactly this, e.g.

[myObject setPrimitiveValue:@"hello" forKey:@"property"]

,或使用动态生成的访问器方法:

or, using the dynamically generated accessor methods:

[myObject setPrimitiveProperty:@"hello"]

但您应该阅读文档,因为有一些特殊注意事项。

But you should read the documentation of that method, because there are some "Special Considerations".

不同的方法可以是创建嵌套的受管对象上下文,并对该上下文进行所有修改。仅当保存子上下文时,更改才会传播到父上下文。

A different approach could be to create a "nested managed object context" and do all the modifications on that child context. Only when the child context is saved, the changes are propagated to the parent context.

这篇关于更改NSManagedObject属性而不触发委托方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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