从继承自UIVIewcontroller的类继承(xamarin和c#)

时间:2014-01-22 13:50:05

标签: c# ios inheritance uiviewcontroller xamarin

我有一个继承自UIViewController的类:

public class A : UIViewController {

  public A():base("A",null){
      //implementation
  }

  //Also it has the ViewDidLoad() and DidReceiveMemoryWarning(), etc.
}

现在我有一个B级继承自A:

public class B : A {

  public A():base(){
      //implementation
  }

  //Also it has the ViewDidLoad() and DidReceiveMemoryWarning(), etc.
}

然后我创建一个B类实例:

B b = new b();

但是当屏幕出现时,它会抛出

“无法在iOS.B上找到选择器setCancelButton:”

所以问题是:如何从子类访问从UIViewController继承的类(.xib中的项目)?

1 个答案:

答案 0 :(得分:1)

你必须在每个在Objective-C上注册它们的类上放置一个属性:

[Register("A")]
public class A : UIViewController { }

[Register("B")]
public class B : A { }