[Mono-osx] how override an Objective C method?
Eric Slosser
eric.slosser at v-fx.com
Wed Oct 27 16:35:38 EDT 2010
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);
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/20101027/e7179b96/attachment-0001.html
More information about the Mono-osx
mailing list