101
Starting with MonoMac 5.4, calling Dispose on the returned
102
notification token will also remove the observer for you,
103
making the code shorter. For example:
108
NSObject notificationToken;
112
notificationToken = NSNotificationCenter.DefaultCenter.AddObserver (FooBar.ClockNotification, OnClockChange);
115
void OnClockChange (NSNotification notification)
117
Console.WriteLine ("The ClockNotification message was posted");
122
notificationToken.Dispose ();
127
<related type="sample" href="http://samples.xamarin.com/Samples/ByGuid?guid=67b46eb2-81d9-477f-a448-18e68db1227b">AppPrefs</related>
128
<related type="sample" href="http://samples.xamarin.com/Samples/ByGuid?guid=23a2571b-45eb-4889-bb67-d88937cb68c1">monocatalog</related>
102
131
<Member MemberName=".ctor">
147
182
<AssemblyVersion>0.0.0.0</AssemblyVersion>
186
<AttributeName>System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)</AttributeName>
150
190
<Parameter Name="t" Type="MonoMac.Foundation.NSObjectFlag" />
153
193
<param name="t">Unused sentinel value, pass NSObjectFlag.Empty.</param>
154
<summary>Constructor to call on derived classes to skip initialization and merely allocate the object.</summary>
194
<summary>Constructor to call on derived classes when the derived class has an [Export] constructor.</summary>
156
<para>This constructor should be called by derived classes when they completely construct the object in managed code and merely want the runtime to allocate and initialize the NSObject. This is required to implement the two-step initialization process that Objective-C uses, the first step is to perform the object allocation, the second step is to initialize the object. When you invoke the constructor that takes the NSObjectFlag.Empty you taking advatnage of a direct path that goes all the way up to NSObject to merely allocate the object's memory and bind the Objective-C and C# objects together. The actual initialization of the object is up to you.</para>
157
<para>This constructor is typically used by the binding generator to allocate the object, but prevent the actual initialization to take place. Once the allocation has taken place, the constructor has to initialize the object. With constructors generated by the binding generator this means that it manually invokes one of the "init" methods to initialize the object.</para>
158
<para>It is your responsability to completely initialize the object if you chain up using the NSObjectFlag.Empty path.</para>
159
<para>In general, if your constructors invokes the NSObjectFlag.Empty base implementation, then it should be calling an Objective-C init method. If this is not the case, you should instead chain to the proper constructor in your class. </para>
160
<para>The argument value is ignored and merely ensures that the only code that is executed is the construction phase is the basic NSObject allocation and runtime type registration. Typically the chaining would look like this:</para>
196
<para>This constructor should be called by derived classes when they are initialized using an [Export] attribute. The argument value is ignore, typically the chaining would look like this:</para>
164
// The NSObjectFlag merely allocates the object and registers the
165
// C# class with the Objective-C runtime if necessary, but no actual
166
// initXxx method is invoked, that is done later in the constructor
168
// This is taken from MonoMac's source code:
170
[Export ("initWithFrame:")]
171
public UIView (System.Drawing.RectangleF frame) : base (NSObjectFlag.Empty)
173
// Invoke the init method now.
174
var initWithFrame = new Selector ("initWithFrame:").Handle;
176
Handle = MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSend_RectangleF (this.Handle, initWithFrame, frame);
178
Handle = MonoMac.ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_RectangleF (this.SuperHandle, initWithFrame, frame);
199
public class MyClass : BaseClass {
200
[Export ("initWithFoo:")]
201
public MyClass (string foo) : base (NSObjectFlag.Empty)
329
359
<param name="observer">To be added.</param>
330
360
<param name="aSelector">To be added.</param>
331
<param name="aName">To be added.</param>
332
<param name="anObject">To be added.</param>
362
<para>Optional name that you want to register with and filter delivery by this name. Use null if you do not want filtering to take place.</para>
363
<para tool="nullallowed">This parameter can be <see langword="null" />.</para>
365
<param name="anObject">
366
<para>The object that we want to receive notifications from, or null for receiving the specified notifications sent by all objects.</para>
367
<para tool="nullallowed">This parameter can be <see langword="null" />.</para>
333
369
<summary>Low-level add-bserver API</summary>
502
538
<param name="aName">To be added.</param>
503
<param name="anObject">To be added.</param>
539
<param name="anObject">
540
<para>The reference object posting this notification, can be null.</para>
541
<para tool="nullallowed">This parameter can be <see langword="null" />.</para>
504
543
<summary>To be added.</summary>
505
544
<remarks>To be added.</remarks>
529
568
<param name="aName">To be added.</param>
530
<param name="anObject">To be added.</param>
531
<param name="aUserInfo">To be added.</param>
569
<param name="anObject">
570
<para>The reference object posting this notification, can be null.</para>
571
<para tool="nullallowed">This parameter can be <see langword="null" />.</para>
573
<param name="aUserInfo">
574
<para>To be added.</para>
575
<para tool="nullallowed">This parameter can be <see langword="null" />.</para>
532
577
<summary>To be added.</summary>
533
578
<remarks>To be added.</remarks>
586
631
<param name="observer">To be added.</param>
587
<param name="aName">To be added.</param>
588
<param name="anObject">To be added.</param>
633
<para>Optional name that you registered. Use null if you do not want filtering to take place.</para>
634
<para tool="nullallowed">This parameter can be <see langword="null" />.</para>
636
<param name="anObject">
637
<para>The object that you originally registered interest in.</para>
638
<para tool="nullallowed">This parameter can be <see langword="null" />.</para>
589
640
<summary>To be added.</summary>
590
641
<remarks>To be added.</remarks>