我最近尝试将UITextField子类化并将委托设置为我自己(发现这个尝试解决了我的问题:http://www.cocoabuilder.com/archive/cocoa/241465-iphone-why-can-a-uitextfield-be-its-own-delegate.html)
@interface MyObject :UITextField <UITextFieldDelegate>
@end
@implementation MyObject
-(id) initWithFrame:(CGRect) frame
{
if((self=[super initWithFrame:frame]))
{
self.delegate=self;
}
return self;
}
-(BOOL) respondsToSelector:(SEL)selector
{
NSLog(@"responds to selector");
return [super respondsToSelector:selector];
}
// Implement all the missing methods
@end
调用接口上定义的方法会导致无限递归。我在Apple文档中没有看到任何定义在一个委托在场的情况下responsesToSelector应该如何表现的内容。
答案 0 :(得分:5)
respondsToSelector
的{{3}}声明如下:
您无法测试是否有对象 从其超类继承一个方法 通过发送respondsToSelector:到 使用super关键字的对象。 [..] 因此,发送respondsToSelector: 超级相当于发送它 自我。相反,你必须调用 NSObject类方法 instancesRespondToSelector:直接 在对象的超类
上
这似乎可能是您的递归问题的原因。我不知道代表的东西是否相关。只是一个猜测。