MonoTouch 绑定

对绑定不了解的,请参考这篇文章 http://www.cnblogs.com/beginor/archive/2012/04/22/2465441.html

本文只要讲述上文没有提到的

1.构造函数

在MonoTouch绑定中,构造函数名是固定的,都是 Constructor,返回类型:IntPtr.

Obj-C 代码:

-(id)initWithCenterViewController:(UIViewController *)centerViewController leftDrawerViewController:(UIViewController *)leftDrawerViewController rightDrawerViewController:(UIViewController *)rightDrawerViewController;

绑定到MonoTouch:

[Export ("initWithCenterViewController:leftDrawerViewController:rightDrawerViewController:")]
IntPtr Constructor (UIViewController centerViewController, UIViewController leftDrawerViewController, UIViewController rightDrawerViewController); 

2.代码块

在Obj-C中,代码块很常用.它和.NET的Lamda表达式相似.可以绑定到委托(Delegate).

Obj-C代码:

 -(void)setDrawerVisualStateBlock:(void(^)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible))drawerVisualStateBlock;
绑定到MonoTouch时,分两部分:

delegate void SetDrawerVisualStateBlockCallback (MMDrawerController  drawerController, MMDrawerSide drawerSide, float percentVisible);
[Export ("setDrawerVisualStateBlock:")] void setDrawerVisualStateBlock (SetDrawerVisualStateBlockCallback drawerVisualStateBlock);

在实际调用时:

this.drawerController.setDrawerVisualStateBlock ((MMDrawerController  drawerController, MMDrawerSide drawerSide, float percentVisible)=>{
            Console.WriteLine("setDrawerVisualStateBlock");
});

 

3.委托(Delegate)

这个比较直接,和.NET相似。

Obj-C代码:

@protocol FPPopoverControllerDelegate <NSObject> @optional - (void)popoverControllerDidDismissPopover:(FPPopoverController *)popoverController; - (void)presentedNewPopoverController:(FPPopoverController *)newPopoverController 
          shouldDismissVisiblePopover:(FPPopoverController*)visiblePopoverController; @end
@property(nonatomic,assign) id<FPPopoverControllerDelegate> delegate;

绑定到MonoTouch时,也分两部分:

[Model, BaseType (typeof(NSObject))] interface FPPopoverControllerDelegate
    {
        [Export ("popoverControllerDidDismissPopover:")] void popoverControllerDidDismissPopover (FPPopoverController popoverController);

        [Export ("shouldDismissVisiblePopover:visiblePopoverController")] void shouldDismissVisiblePopover (FPPopoverController newPopoverController, FPPopoverController visiblePopoverController);
    }
        [Export("delegate")]
        NSObject WeakDelegate { get; set; }

        [Wrap("WeakDelegate")]
        FPPopoverControllerDelegate Delegate { get; set; }

你可能感兴趣的:(绑定,构造函数,MonoTouch)