[Mono-osx] how override an Objective C method?
Geoff Norton
gnorton at novell.com
Sat Oct 30 15:04:50 EDT 2010
Eric,
I took a look at this again, and we did definitely have a bug in
base.RespondsToSelector () whch is now fixed, thanks for the heads up
-g
From: Eric Slosser <eric.slosser at v-fx.com>
Date: Wed, 27 Oct 2010 16:35:38 -0400
To: <gnorton.novell at gmail.com>
Cc: mono-osx <mono-osx at lists.ximian.com>, Miguel de Icaza
<Miguel at novell.com>
Subject: Re: [Mono-osx] how override an Objective C method?
On Oct 27, 2010, at 2:23 PM, Geoff Norton wrote:
> As miguel said, you're wanting to bind a static method so you need something
> like this:
> [Export ("respondsToSelector:")]
> public static bool RespondsToSelector (Selector sel)
Actually, Miguel was pointing out the opposite, that I had written "+", when
I meant "-".
Having gone back and re-read the Apple documentation on -[NSObject
respondsToSelector:], I see I was wrong to try to call the base
implementation of "respondsToSelector", I should have been calling
+[NSObject instancesRespondToSelector:].
By combining your code with the Apple info I got this which behaves as I
wanted.
public override bool RespondsToSelector (Selector sel)
{
bool result = Messaging.bool_objc_msgSend_intptr ( Class.GetHandle
("WhateverYourSuperClassIs"), Selector.GetHandle
("instancesRespondToSelector:"), sel.Handle);
Console.WriteLine("responds to: {0} {1}", result ? "yes " : "no ",
sel.Name <http://sel.Name> );
return result;
}
> The bigger question is why do you want to override this method? It's very odd
> that you would want to do this, since the NSObject instance and objc-runtime
> should handle this for you.
I'm not going to change the return value, I just want to report it so I can
see what selectors my object is being asked about. It's a generally useful
technique, because you can see what selectors Cocoa is wondering about, and
not spend time implementing the ones it doesn't.
My specific use in this case was to figure out why a certain delegate method
that I had implemented wasn't getting called.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20101030/cddfb965/attachment.html
More information about the Mono-osx
mailing list