[UIKit] Store the delegate in a local variable in the UIContextMenuInteraction. by rolfbjarne · Pull Request #19386 · dotnet/macios (original) (raw)
The UIContextMenuInteraction type is a bit uncommon: the delegate is passed as
an argument to the constructor, instead of setting the 'delegate' property
later on (in fact, the 'delegate' property is read-only).
Typically, the generated WeakDelegate property will store the value in an instance field:
object? __mt_WeakDelegate_var;
public virtual NSObject? WeakDelegate {
get {
NSObject? ret = /* ... */;
MarkDirty ();
__mt_WeakDelegate_var = ret;
return ret!;
}
}
And in order to have the same behavior in the UIContextMenuInteraction we need to
store the delegate passed to the constructor as well, so do that.
Otherwise the GC will eventually collect the delegate, and things stop working.
Ref: dotnet/maui#18449