[MonoTouch] binding my own protocol

Nic Wise nicw at fastchicken.co.nz
Wed Dec 7 11:37:31 EST 2011


Thanks - I'll give that a go.

On Wed, Dec 7, 2011 at 16:01, Robert Jordan <robertj at gmx.net> wrote:
> 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
>
> _______________________________________________
> MonoTouch mailing list
> MonoTouch at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch



-- 
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2


More information about the MonoTouch mailing list