NSObjectFlag 类

定义

MonoTouch 框架使用的 Sentinel 类。

public class NSObjectFlag
type NSObjectFlag = class
继承
NSObjectFlag

注解

NSObjectFlag 类的唯一用途是用作 NSObject 类层次结构中的 sentinel,以确保实际的对象初始化仅在 NSObject 中发生。

使用 NSObjectFlag.Empty 链接构造函数时,唯一会发生的是对象实例的分配,将不调用基类中的任何 init: 方法。 如果代码依赖于此进行初始化,则由你负责直接调用正确的 init 方法。 例如:

// 
// 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);
	}
}

或者,如果需要一个基类来初始化自身,则应调用采用某些参数的其他构造函数之一。

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.
	}
}

字段

Empty

Sentinel 实例。

适用于