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: Sat, 25 Jul 2009 22:14:28 +0200
Convoluted? I don't see it that way.
This particular text field needs to limit its number of characters to
a given interval. Why should any other object have to deal with that
problem when the field itself can take care of it? Still, it might be
the case, though it also might not be the case, that another object
wants to participate in the editing session. The flow of events here
is as follows: the field takes care of its own business first
(limiting the number of characters) and then allows the delegate, if
any, to have its shot at the editing process.
And since limiting the number of characters is always going to happen
but having extra work might not, it does not make sense to me to
burden an extra object with both tasks. Let the field take care of its
own business since it can do so cleanly. All other objects shouldn't
care.
In any case, none of this has anything to do with the problem I
mentioned. The sample application has no extra delegates and, in fact,
does nothing whatsoever other than having the field be its own delegate.
Incidentally, I tried the same thing with a Mac application and it
works fine. It's only under the iPhone SDK that setting a text field
to be its own delegate causes a problem. The documentation for
UITextField says nothing about any restrictions about which objects
can and cannot be the field delegate and I can't see a reason why the
field can't be its own delegate, so I'm inclined to think that this is
a real bug in the iPhone SDK. As usual, though, I'd like to hear other
people's input on the matter, because I might be missing something.
Wagner
On Jul 25, 2009, at 9:47 PM, Luke the Hiesterman wrote:
Wow, this all sounds very convoluted. If you must have two levels of
delegation (which sounds like flawed design, to me) then I would
suggest doing it in a more straightforward manner. That is, make a
delegate for UITextField, and then have another delegate protocol
for that object so it can have its own delegate. Even better, just
wrap everything you need into the object you set as delegate to
UITextField and don't try to shove weird things into a subclass.
Luke
On Jul 25, 2009, at 12:39 PM, WT wrote:
The reason is simple, though probably not obvious.
I still might need the text field to have an "outside" delegate,
which I maintain by having an additional outlet reserved for that
delegate. Then, I override -delegate to return that outlet and -
setDelegate: to set it.
That way, the field can be its own true delegate and do its job,
while also allowing an outside object to serve as a delegate and
participate in the editing session. As far as the outside world is
concerned, it's business as usual.
But once I have an overridden -setDelegate:, I can't use
self.delegate = self to set the field as its own true delegate,
because that will execute the overridden method.
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