KVO vs NSNotification vs protocol / delegates? [英] KVO vs NSNotification vs protocol/delegates?

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

问题描述

虽然我有一些想法可以使用,但确切用法仍然不清楚。有人可以用例子解释......?谢谢。

Though I have some idea which to use when but the exact usage is still not clear to me. Can someone explain with example...? Thanks.

推荐答案

如果只想与一个对象交谈,请使用委托。例如,tableView有一个委托 - 只有一个对象负责处理它。

Use a delegate if you want to talk to only one object. For example, a tableView has a delegate - only one object should be responsible for dealing with it.

如果你想告诉大家发生了什么事情,请使用通知。例如,在内存不足的情况下,会发送通知,告知您的应用程序存在内存警告。由于您应用中的大量对象可能希望降低其内存使用量,因此这是一个通知。

Use notifications if you want to tell everyone that something has happened. For example in low memory situations a notification is sent telling your app that there has been a memory warning. Because lots of objects in your app might want to lower their memory usage it's a notification.

我认为KVO根本不是一个好主意并且尽量不要使用但是,如果你想知道一个房产是否已经改变,你可以听取更改。

I don't think KVO is a good idea at all and try not to use it but, if you want to find out if a property has changed you can listen for changes.

希望有所帮助。

PS 这总结了我认为KVO被打破的原因

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

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