Re: IB instantiating objects
Re: IB instantiating objects
- Subject: Re: IB instantiating objects
- From: Gmail <email@hidden>
- Date: Tue, 24 Mar 2009 10:31:51 +0700
On Mar 24, 2009, at 10:01 AM, Ashley Clark wrote:
On Mar 23, 2009, at 9:30 PM, Gmail wrote:
Thanks! I think that document explains everything I need to know to
take control over IB.
This is more Objective-C related by maybe you have a quick tip. My
first tests suggest that my method for overriding is not correct
because overriding "init" is getting invoked from all sorts of
other classes (like NSFileManager to name a few) when the NIB is
loading. I use class_getInstanceMethod (with the instance of the
custom class I registered with the objective-c runtime) to get the
method then replace the implementation with my function pointer.
This method worked before for overriding drawRect: in NSView so I'm
not sure what is different now. Any ideas?
class_getInstanceMethod searches the entire class hierarchy. So, if
the class you're working with didn't override that implementation
you'll be replacing the superclass' implementation.
If you call class_addMethod on self with the result of
class_getMethodImplemenation you'll be adding it to the subclass if
it's not already overridden. After that calling
method_exchangeImplementations will only affect that class.
Hmmm, I overrode the superclasses implementation, i.e. NSObject, which
sounds about right considering the results.
So, I need to be using class_addMethod for "init" because my new class
has no implementation for that method. I think the previous attempt to
override NSView worked because drawRect: DID have an implementation
for that selector already added to the runtime, which is not the case
with my new class. Thank you Ashley I think you are correct.
Is there anyway way to determine if a class has an implementation for
a method so I can decide to add a new method or override an existing?
As it stands I don't know in code when I should add or exchange
implementations.
Ashley
On Mar 24, 2009, at 8:02 AM, Jonathan Hess wrote:
Hey Josef -
When IB instantiates an object in a NIB file that has the custom
class set, it will instantiate it with either init,
initWithFrame:, or initWithCoder: depending on the type of object.
Here's a link tot he relevant documentation:
http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#/
/apple_ref/doc/uid/10000051i-CH4-SW19
Jon Hess
On Mar 23, 2009, at 5:36 PM, Gmail wrote:
NO, it supports subclassing. Do you know what method I could
override (and return my instance) before the NIB is loaded so I
can control it's isntance variables? I think maybe a low-level
protocol like init could perhaps work. Thanks.
On Mar 24, 2009, at 12:15 AM, Bill Bumgarner wrote:
On Mar 22, 2009, at 6:26 PM, Gmail wrote:
Is there anyone who is aware how this was accomplished by the
other bridges or if I can force IB to not instantiate the
classes, or maybe replace the instance with my own? It seems
like I need a way to access the instances of those classes
inside the nib but I don't think that can be done. Any ideas
are greatly appreciated. Thank you.
RubyCocoa and PyObjC work by creating the class before the NIB
is loaded. From your description, it sounds like your bridge
doesn't support subclassing. If so, that'll make your bridge
considerably more difficult to integrate with Cocoa.
b.bum
Regards,
Josef
Regards,
Josef
_______________________________________________
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