ios - iOS 中 Target Action 和 Key Value Observer 的区别

标签 ios design-patterns

两者有什么区别?在我看来,两者看起来都在做同样的事情,即通知事件观察者有关某个事件的信息。

我读了这篇文章 http://www.raywenderlich.com/46988/ios-design-patterns关于上述两种事件处理技术所使用的实际模式,但未能理解命令模式与观察者模式有何不同,或者我是否遗漏了什么。

最佳答案

在目标 Action 中,控制事件的对象被告知从该事件触发什么。 iOS 开发人员最常使用它的不是 NSInvocation,而是 Interface Builder。发送者通常是一个 UIControl。

在 NSNotification 中,通知会广播给正在监听特定事件的任何人。这些通知非常通用,可以包含任何信息。听众可能关心也可能不关心发送者是谁。

在 KVO 中,监听器关注特定对象的特定属性。

关于ios - iOS 中 Target Action 和 Key Value Observer 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32097105/

相关文章:

ios - "This item cannot be shared. Please select a different item."WhatsApp iOS 共享扩展失败消息

ios - ApplicationIconBadgeNumber 没有在重新安装我的 ipad 应用程序时重置。

c++ - cpp中如何防止多个线程同时使用单例类实例

php - 为什么类名不回退到命名空间中的全局类名?

iOS Facebook SDK 3.1 openActiveSessionWithReadPermissions : Detect when user is not granting access

ios - Assets 目录中的 Launch Image 只有 2x 和 R4 的空间

ios - 捕获其父 View 框架外的 subview 上的触摸(在多个层上)

ios - Controller 中的 NSTimer,如何通知 View ?

c# - 考虑 C# 中的 "disposable"关键字

.net - 如何不删除其他对象引用的缓存项