[Mono-osx] [MonoMac] "Apply Protocol to Class"

Duane Wandless duane at wandless.net
Thu Jan 20 14:16:41 EST 2011


I ran into a usage pattern that seems common.  In Interface Builder define
an NSTableView and an NSArrayController.  Set the NSArrayController as the
outlet for the NSTableView's dataSource and delegate.  Then specify the
NSArrayController to be a custom class.

The issue is that we of course cannot do this:

class CustomArrayController : NSArrayController, NSTableViewDataSource,
NSTableViewDelegate

One solution is to manually add the NSTableViewDataSource/Delegate methods
like this to the NSArrayController.

                [Export ("tableView:objectValueForTableColumn:row:")]
                NSObject GetObjectValue (NSTableView tableView,
NSTableColumn tableColumn, int row)


Another solution is to manually set the dataSource on the NSTableView.
 tableView.DataSource = new
CustomTableViewDataSource(customArrayController).

In the first solution, who wants to remember or lookup the export
decoration?
In the second solution, that defeats one of the main features of IB.

I do think this usage pattern extends beyond this example.  You can set the
dataSource/delegate to be the File's Owner, etc.  One of the benefits of
Cocoa is that any object can implement a selector.  MM solves this with the
Export but again you have to know the selector.  Providing a means to easily
add the selectors for a given protocol to a class would be very ideal.

Duane
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20110120/183824bd/attachment.html 


More information about the Mono-osx mailing list