• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [iPhone] Why can't a UITextField be its own delegate?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >[iPhone] Why can't a UITextField be its own delegate? (From: WT <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: Brian Slick <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: WT <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: Luke the Hiesterman <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: WT <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: Kyle Sluder <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: WT <email@hidden>)
 >Re: [iPhone] Why can't a UITextField be its own delegate? (From: Kyle Sluder <email@hidden>)

  • Prev by Date: The correct NSPredicate format for one-to-many relationship in Core Data
  • Next by Date: Re: [iPhone] Why can't a UITextField be its own delegate?
  • Previous by thread: Re: [iPhone] Why can't a UITextField be its own delegate?
  • Next by thread: Re: [iPhone] Why can't a UITextField be its own delegate?
  • Index(es):
    • Date
    • Thread