我有一个IOS代码要在c#中重写这个id<UIGestureRecognizerDelegate> gestureDelegate;
我怎样才能在c#中重写它?
@property (weak, nonatomic) id<UIGestureRecognizerDelegate> gestureDelegate;
其实我声明它像UIGestureRecognizerDelegate gestureDelegate;
但是它是对的吗?
如果我理解正确,id
就像C#中的var
一样?
如果是这样我怎么能将它声明为类参数?
答案 0 :(得分:4)
C#interface
与Objective-C中的protocol
类似,id<UIGestureRecognizerDelegate>
表示该对象实现UIGestureRecognizerDelegate
中定义的方法。因此,C#中的相同内容可能是(主要思想,未在IDE中测试):
interface UIGestureRecognizerDelegate {
public bool gestureRecognizerShouldBegin(UIGestureRecognizer gestureRecognizer);
}
class Example {
public UIGestureRecognizerDelegate gestureDelegate; //the equivalent
}
符合界面的类:
public class ExampleViewController:UIViewController,UIGestureRecognizerDelegate {
var example = Example();
public ExampleViewController() {
this.example.gestureDelegate = this;
}
//implements the methods of interface UIGestureRecognizerDelegate
public bool gestureRecognizerShouldBegin(UIGestureRecognizer gestureRecognizer) {
//......
}
}