I am using xamarin to develop a Mac app, and somewhere in my program I want to set the tag of a NSView. However, the tag property is readonly for NSView, so I'm searching for a way to create a subclass where tag is writable. Is there any suggestion about how I should write the subclass? thanks
Asked
Active
Viewed 598 times
2 Answers
0
public class MyNSView : NSView
{
public nint _tag;
public new nint Tag
{
get
{
return _tag;
}
set
{
_tag = value;
}
}
Be aware that this is not longer the NSView
Tag.
Using your custom NSView
Tag
var view = new MyNSView ();
view.Tag = 100;

pinedax
- 9,246
- 2
- 23
- 30
0
I found a workaround to get viewWithTag
working:
@IBInspectable
override var tag: Int {
get { return super.tag }
set { super.tag = newValue }
}
In IB the NSView's Tag is still greyed out, but there is also a subclass's Tag available for setting a value.
Still, to my best effort, I can't find a logical reason for Tag to be greyed out in IB.

cyanide
- 3,885
- 3
- 25
- 33