respondsToSelector
来源:互联网 发布:闲来打麻将赢钱软件 编辑:程序博客网 时间:2024/06/06 04:08
http://stackoverflow.com/questions/4574465/objective-c-respondstoselector-question
First of all, the name of a method (its selector) includes all subparts and colon characters, as mvds said.
Second of all, the method -respondsToSelector:
is not called by the runtime, it's usually called by the user (yourself or APIs that want to know if a delegate, for example, responds to an optional method of the protocol).
When you send a message to an object, the runtime will look for the implementation of the method in the class of the object (through the object's isa pointer). It's equivalent to sending-respondsToSelector:
although the message itself is not dispatched. If the implementation of the method is found in the class or in its superclasses, it's called with all the arguments you passed in.
If not, then the runtime gives the message a second chance to be executed. It will start by sending the message+ (BOOL)resolveInstanceMethod:(SEL)name
to the class of the object: this method allows you to add the method at runtime to the class: if this message returns YES, it means it can redispatch the message.
If not it gives the message a third chance to be executed, it sends - (id)forwardingTargetForSelector:(SEL)aSelector
with the selector, this method can return another object that may be able to respond to the selector on behalf of the actual receiver, if the returned object can respond, the method is executed and the value is returned as if it was returned by the original message.
If the returned object is nil or self (to avoid infinite loops), the runtime gives the message a fourth chance to execute the method… It sends the message- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
to get a method signature in order to build an invocation. If one is provided then an invocation is sent through the message- (void)forwardInvocation:(NSInvocation *)anInvocation
. In this method you can parse the invocation and build other messages to send to other targets in any ways you want, and then you can set the return value of the invocation… That value will act as the return value of the original message.
Finally, if no method signature is returned by the object, then the runtime sends the message- (void)doesNotRecognizeSelector:(SEL)aSelector
to your object, the implementation of this method in NSObject class throws an exception. You can override this method to silently fail at handling messages.
- respondsToSelector
- respondsToSelector
- respondsToSelector instancesRespondToSelector
- respondsToSelector instancesRespondToSelector
- respondsToSelector instancesRespondToSelector
- respondsToSelector使用
- respondsToSelector的妙用
- respondsToSelector的相关使用
- isKindOfClass, isMemberOfClass, respondsToSelector, instancesRespondToSelector
- respondsToSelector的相关使用
- respondsToSelector的相关使用
- respondsToSelector的相关使用
- respondsToSelector的作用
- respondsToSelector的相关使用
- isKindOfClass& isMemberOfClass respondsToSelector& instancesRespondToSelector
- respondsToSelector的相关使用
- respondsToSelector的相关使用
- respondsToSelector的相关使用
- conversion to dalvik format failed with error 1的解决办法
- 文件系统那些事-第2篇 不可不知的文件系统特性
- 分享一段用VC调用默认打印机打印菜单的程序
- ESB是中间件的未来?抑或是昙花一现?
- hdu1027 全排列 qsort
- respondsToSelector
- ios平台上sqlite3数据库简单实例~~~~~~
- 通过 WebSphere MQ 遥测传输 (MQTT) 将 Android 手机引入物联网
- 子网划分细节--百度百科和大部分文档都不求甚解
- C#数据库事务原理及实践
- Hibernate的fetch
- 文件系统那些事-第3篇 影响文件系统性能的关键因素:存储块分配和布局策略
- Unity 数据管理
- 今天最囧的事,你有没有。。