Skip to content

Instantly share code, notes, and snippets.

@chamons
Created April 7, 2015 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/2f098ede8e1e4d0c4881 to your computer and use it in GitHub Desktop.
Save chamons/2f098ede8e1e4d0c4881 to your computer and use it in GitHub Desktop.
using System;
using Foundation;
using AppKit;
using CoreGraphics;
using System.Linq;
namespace DoubleClickBug
{
class TableSetup
{
internal static NSView SetupTableView (CGRect frame)
{
NSTableView tableView = new NSTableView () {
Frame = frame
};
tableView.AddColumn (new NSTableColumn ("Values"));
tableView.AddColumn (new NSTableColumn ("Data"));
tableView.DoubleClick += (object sender, EventArgs e) => Console.WriteLine ("DClick?");
tableView.DataSource = new TableDataSource ();
tableView.Delegate = new TableDelegate ();
NSClipView clipView = new NSClipView (frame) {
AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable
};
clipView.DocumentView = tableView;
return clipView;
}
}
class TableDelegate : NSTableViewDelegate
{
const string identifer = "myCellIdentifier";
static string [] NumberWords = new[] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
public override NSView GetViewForItem (NSTableView tableView, NSTableColumn tableColumn, nint row)
{
NSTextField view = (NSTextField)tableView.MakeView (identifer, this);
if (view == null) {
view = new NSTextField ();
view.Identifier = identifer;
view.Bordered = false;
view.Selectable = false;
view.Editable = false;
}
if (tableColumn.Identifier == "Values")
view.StringValue = (NSString)row.ToString ();
else
view.StringValue = (NSString)NumberWords [row];
return view;
}
}
class TableDataSource : NSTableViewDataSource
{
public override nint GetRowCount (NSTableView tableView)
{
return 10;
}
}
public partial class AppDelegate : NSApplicationDelegate
{
MainWindowController mainWindowController;
public override void DidFinishLaunching (NSNotification notification)
{
mainWindowController = new MainWindowController ();
mainWindowController.Window.MakeKeyAndOrderFront (this);
mainWindowController.Window.ContentView.AddSubview (TableSetup.SetupTableView (new CGRect (0, 0, 200, 200)));
GC.Collect (2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment