Re: [iPhone] Why can't a UITextField be its own delegate?
Re: [iPhone] Why can't a UITextField be its own delegate?
- Subject: Re: [iPhone] Why can't a UITextField be its own delegate?
- From: WT <email@hidden>
- Date: Sun, 26 Jul 2009 00:49:26 +0200
On Jul 26, 2009, at 12:23 AM, Kyle Sluder wrote:
There is no reason for any outside entity to want to refer to
super.delegate. In fact, unless I'm wrong, I don't think it's even
possible
to retrieve super.delegate from the custom instance.
Ooh, I think we've found your bug.
I don't think so.
Internally, UITextField is going to use self.delegate to get its
delegate, following the correct accessor behavior. You've gone and
replaced -delegate to return self.
As I said earlier, -delegate returns the outside delegate, not self.
But, in the sample application, there is no outside delegate so, yes, -
delegate returns self. But this shouldn't be a problem because the
custom text field implements ALL methods of the UITextFieldDelegate
protocol.
But the delegate pattern says that
messages which this object does not understand should be forwarded to
the delegate.
Not a problem. See above.
This means that a class with a delegate needs to
implement -respondsToSelector: this way:
- (BOOL)respondsToSelector:(SEL)aSelector {
return [super respondsToSelector:aSelector]
|| [self.delegate respondsToSelector:aSelector];
}
[super respondsToSelector:aSelector] is, according to the docs,
identical to [self respondsToSelector:aSelector]. And since
self.delegate, in the sample app, returns self, this is indeed an
infinite loop. But, does UITextField implement -respondsToSelector: as
above?
Since -delegate is going to return self, -respondsToSelector: is going
to result in infinite recursion.
True. So, the question is, again: does UITextField implement -
respondsToSelector: as above?
Wagner
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden