Re: Why would a defined selector not be found at runtime?
Re: Why would a defined selector not be found at runtime?
- Subject: Re: Why would a defined selector not be found at runtime?
- From: Ken Tozier <email@hidden>
- Date: Thu, 12 May 2005 14:25:34 -0400
On May 12, 2005, at 2:06 PM, Douglas Davidson wrote:
On May 12, 2005, at 10:53 AM, Ken Tozier wrote:
Allocating like this:
NSDisclosureButtonCell *result =
[[NSDisclosureButtonCell alloc] initWithControlSize: inControlSize];
fails with the exact same error message as:
NSDisclosureButtonCell *result = [NSDisclosureButtonCell
alloc];
// next line shows a valid object in "result"
NSLog(@"result = %@", result);
// chokes here
[result initWithControlSize: inControlSize];
error log:
*** -[NSDisclosureButtonCell initWithControlSize:]: selector not
recognized
I've read in multiple places that you should never split it up
like you're doing. It should always be alloc/init'd together.
Hadn't heard that. Although I never alloc/init in two steps unless
there is a problem and I want to see what's happening...
The primary reason you should not alloc/init in two steps is that
the init may return a different object. It can be done correctly--
the correct code would be
NSDisclosureButtonCell *result = [NSDisclosureButtonCell alloc];
NSLog(@"result = %x", result);
result = [result initWithControlSize:inControlSize];
but the quoted code shows some of the obvious errors that make this
a bad idea: (1) the return value of initWithControlSize: should
replace result, but does not; (2) you cannot in general send any
message other than an initializer to an alloc'd but uninitialized
object, so you should not use %@ with result here.
Good to know, thanks.
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden