In my Project I have a View with Controller called TaskOverviewView with just a NSTextField, which I'd like to use like a widget. In a NSWindow I have a NSCustomView and a NSScrollView as well. On booth I try to add a instance of the view of TaskOverviewViewController as a Subview using the addSubview(NSView) method. While it works on the ScrollView the widget isn't visible on the CustomView instead.
Code:
Code of the TaskOverviewViewController:
using System;
using System.Collections.Generic;
using System.Linq;
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace GetTheMilk.MacGUI
{
public partial class TaskOverviewViewController : MonoMac.AppKit.NSViewController
{
#region Constructors
// Called when created from unmanaged code
public TaskOverviewViewController (IntPtr handle) : base (handle)
{
Initialize ();
}
// Called when created directly from a XIB file
[Export ("initWithCoder:")]
public TaskOverviewViewController (NSCoder coder) : base (coder)
{
Initialize ();
}
// Call to load from the XIB/NIB file
public TaskOverviewViewController () : base ("TaskOverviewView", NSBundle.MainBundle)
{
Initialize ();
}
// Shared initialization code
void Initialize ()
{
_taskName = new NSTextField();
_taskName.StringValue = "HUHUH";
}
#endregion
//strongly typed view accessor
public new TaskOverviewView View {
get {
return (TaskOverviewView)base.View;
}
}
}
}
the Controller of my StartupWindow:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace GetTheMilk.MacGUI
{
public partial class StartupWindowController : MonoMac.AppKit.NSWindowController
{
#region Constructors
// Called when created from unmanaged code
public StartupWindowController (IntPtr handle) : base (handle)
{
Initialize ();
}
// Called when created directly from a XIB file
[Export ("initWithCoder:")]
public StartupWindowController (NSCoder coder) : base (coder)
{
Initialize ();
}
// Call to load from the XIB/NIB file
public StartupWindowController () : base ("StartupWindow")
{
Initialize ();
}
// Shared initialization code
void Initialize ()
{
}
#endregion
//strongly typed window accessor
public new StartupWindow Window {
get {
return (StartupWindow)base.Window;
}
}
partial void _ButtonClick(NSObject sender)
{
_Label1.StringValue = "Hello";
TaskOverviewViewController widget = new TaskOverviewViewController();
_cview.AddSubview(widget.View);
_scrillView.AddSubview(widget.View);
}
}
}