[MonoTouch] binding my own protocol

Robert Jordan robertj at gmx.net
Wed Dec 7 11:01:44 EST 2011


On 07.12.2011 12:52, Nic Wise wrote:
> Hi there.
>
> I've been reading this:
> http://docs.xamarin.com/ios/tutorials/Events%2c_Protocols_and_Delegates
>
> Am I correct in thinking I can make my own abstract class for a
> protocol I want to use (UIAccessability in this case):
>
> [Register("UIAccessability", Model]
> public abstract class UIAccessability : NSObject
> {
>    //methods and bindings using [Export] in here
>    public virtual string AccessabilityLabel {
>      [Export("accessibilityLabel")]get;
>      [Export("setAccessibilityLabel:")]set;
>    }
> }
>
> Then, on a button, I could do:
>
> UIButton button = whatever's needed to set it up
>
> var acc = button as UIAccessability;
>
> if (acc != null)
>    acc.AccessabilityLabel = "foo!";
>
> etc
>
> Correct? No need to btouch it, as I'm not bringing in a new library -
> it's all in UIKit??

Since UIAccessibility is an informal protocol, Obj-C classes
don't adopt it, and direct bindings won't work as expected
anyway.

Try this extension class:

http://pastebin.com/0bqJaP0B


Robert



More information about the MonoTouch mailing list