1 - Erstellen Sie Ihre XIB-Datei (Beispiel MyView).
2 - in der .cs in die XIB-Datei hinzufügen, um diese statische Konzept Methode verwendet:
partial class MyView : UIView
{
public MyView (IntPtr handle) : base (handle)
{
}
public static MyView Create()
{
var arr = NSBundle.MainBundle.LoadNib ("MyView", null, null);
var v = Runtime.GetNSObject<SomeView> (arr.ValueAt(0));
return v;
}
}
3 - Hinzufügen MyView
zum ViewController
:
public partial class ViewController : UIViewController
{
MyView v;
public ViewController (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
v = MyView.Create();
v.Frame = View.Frame;
View.AddSubview (v);
}
}
Sie können here mehr lesen.
statische Methode Create ist kein statischer Konstruktor. – Grigory
Die Idee hier ist das Erstellen der Xib über eine statische Methode, nicht von einem statischen Konstruktor. – jzeferino
Ich weiß. Sie haben geschrieben, dass die Create-Methode ein statischer Konstruktor ist. Es ist nicht. Es ist eine normale statische Methode aus C# Perspektive. – Grigory