Hi Jamie,

Unfortunately there is no easy way [1] for you to add support for
protocols, but here is a workaround:

class MyView {
  [DllImport ("/usr/lib/libobjc.dylib")]
  static extern IntPtr objc_getProtocol (string proto);

  IntPtr protoUIKeyInput = objc_getProtocol ("UIKeyInput");

  [Export("conformsToProtocol:")]
  public bool Conforms (IntPtr protocol) {
   return protocol == protoUIKeyInput;
   }

  /* and you need to add the implementations for UIKeyView yourself
with the appropriate Export attributes */
}

Rolf

[1] We will be adding an easier way to do this soon by an attribute
you put on your class.

On Sun, Sep 18, 2011 at 10:21 AM, Jamie Briant
<[email protected]> wrote:
> I'm trying to create a simple text editor. I need to implement the
> UIKeyInput protocol on my view.
> I have discovered that in Objective-C this does not work:
>
> @interface MyView : UIView {
> }
> @end
> - (void)insertText:(NSString *)theText {
> }
> - (void)deleteBackward {
> }
> - (void)drawRect:(CGRect)rect {
> }
>
> But this does:
>
> @interface MyView : UIView<UIKeyInput> {
> }
> @end
> - (void)insertText:(NSString *)theText {
> }
> - (void)deleteBackward {
> }
> - (void)drawRect:(CGRect)rect {
> }
>
> That is, putting the protocol in the @interface definition makes the
> difference.
> How do I put a <protocol> on a class?
> Thanks,
> jamie
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to