對綁定不了解的,請參考這篇文章 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; }
4.綁定類别(Category)
這個似乎目前還沒有實作.預計它以後的實作可能是這樣:
namespace XYOrigami
{
delegate void OrigamiAnimationCompleted (bool finished);
[BaseType (typeof(UIView))]
[Category]
interface Origami{
[Export ("showOrigamiTransitionWith:NumberOfFolds:Duration:Direction:completion:")]
void ShowOrigamiTransition (UIView view, int folds, float duration, XYOrigamiDirection direction, OrigamiAnimationCompleted completed);
[Export ("hideOrigamiTransitionWith:NumberOfFolds:Duration:Direction:completion:")]
void HideOrigamiTransition (UIView view, int folds, float duration, XYOrigamiDirection direction, OrigamiAnimationCompleted completed);
}
}
以上推測的依據是從 http://stackoverflow.com/questions/14961716/monotouch-binding-categories-using-category-attribute 而來.回答者 chrisntr 屬于Xamarin 開發團隊.
轉載于:https://www.cnblogs.com/Caiyinsoft/p/3466102.html