简体   繁体   English

iOS委托命名约定 - 应该,将会做

[英]iOS delegate naming conventions - should, will, did

I am looking into naming conventions for iOS controls delegates. 我正在研究iOS控件代理的命名约定。 I am familiar with the should, will, did pattern for delegate methods . 我熟悉委托方法应用,意志,模式 I can see this naming convention used extensively by the Apple APIs. 我可以看到Apple API广泛使用的这种命名约定。 My question is, are there any delegates supplied by apple that have should, will, did methods for a single action? 我的问题是,是否有任何由苹果提供的代表应该,将会采取单一行动的方法吗? eg for row selection: 例如,用于行选择:

shouldSelectRow
willSelectRow
didSelectRow

I have not found a delegate that defines all three. 我还没有找到一个定义所有三个的委托。 My feeling is that 'will' methods are often used in place of should, ie they can return a value in order to cancel the action. 我的感觉是'will'方法通常用于代替should,即它们可以返回一个值来取消动作。

Are there any counter-examples? 有反例吗?

Should methods always return a BOOL value, and tell you the current behavior of an object (But they are never called automatically). 方法总是返回BOOL值,并告诉您对象的当前行为(但它们永远不会自动调用)。 Will methods are delegate methods that get called when an event is about to happen, like 方法是在事件即将发生时调用的委托方法,例如

-(void)applicationWillResignActive...

and "did" methods are also delegate methods that get called after the event took place, like appplicationDidFinishLaunching... 并且“did”方法也是在事件发生后调用的委托方法,如appplicationDidFinishLaunching ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM