NSObjectFlag Classe

Definizione

Classe Sentinel usata dal framework MonoTouch.

public class NSObjectFlag
type NSObjectFlag = class
Ereditarietà
NSObjectFlag

Commenti

L'unico scopo della classe NSObjectFlag è quello di essere usato come sentinel nella gerarchia di classi NSObject per garantire che l'inizializzazione effettiva degli oggetti avvenga solo in NSObject.

Quando si concatenano i costruttori usando NSObjectFlag.Empty, l'unica cosa che verrà eseguita è l'allocazione dell'istanza dell'oggetto, non verranno eseguite chiamate a nessuno dei metodi init: verranno eseguiti i metodi nelle classi di base. Se il codice dipende da questo oggetto per l'inizializzazione, si è responsabili della chiamata diretta del metodo init appropriato. Ad esempio:

// 
// The NSObjectFlag merely allocates the object and registers the
// C# class with the Objective-C runtime if necessary, but no actual
// initXxx method is invoked, that is done later in the constructor
//
// This is taken from Xamarin's source code:
//
[Export ("initWithFrame:")]
public UIView (System.Drawing.RectangleF frame) : base (NSObjectFlag.Empty)
{
	// Invoke the init method now.
	var initWithFrame = new Selector ("initWithFrame:").Handle;
	if (IsDirectBinding) {
		Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSend_RectangleF (this.Handle, initWithFrame, frame);
	} else {
		Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_RectangleF (this.SuperHandle, initWithFrame, frame);
	}
}

In alternativa, se è necessaria una classe di base per inizializzare se stessa, è necessario chiamare uno degli altri costruttori che accettano alcuni parametri.

class MyViw : UIView {
	[Export ("initWithFrame:")]
	public MyView (RectangleF frame) : base (frame)
	{
		// this initialized MyView by calling the UIView constructor
		// that initializes the object from a RectangleF frame.
	}
}

Campi

Empty

Istanza di Sentinel.

Si applica a