[Impromptu] NSTableview in Impromptu

Andrew Sorensen andrew at moso.com.au
Fri Sep 25 02:31:26 GMT 2009


Hi Andreas,

'Value' should be 'value' (lowercase v) and you also need a backing  
array for the array controller.
Here's some code that does what you need.

(define window (objc:make "NSWindow"  
"initWithContentRect:styleMask:backing:defer:"
                           (list 200 200 400 300) 1 2 0))

(objc:call window "orderFront:" 0)
(objc:call window "setTitle:" "MyWindow")

(define contentView (objc:call window "contentView"))

(define tableview (objc:make "NSTableView" "initWithFrame:" '(5 5 390  
280)))
(objc:call contentView "addSubview:" tableview)

(define *array* (objc:call "NSMutableArray" "array"))
(define *arrayController* (objc:make "NSArrayController" "init"))

(objc:call *arrayController* "setContent:" *array*)

(objc:call tableview "bind:toObject:withKeyPath:options:" "content"  
*arrayController* "arrangedObjects" 0)

(define tablecolumn1 (objc:make "NSTableColumn" "initWithIdentifier:"  
"a_column"))
(define tablecolumn2 (objc:make "NSTableColumn" "initWithIdentifier:"  
"b_column"))
(define tablecolumn3 (objc:make "NSTableColumn" "initWithIdentifier:"  
"c_column"))

(objc:call tableview "addTableColumn:" tablecolumn1)
(objc:call tableview "addTableColumn:" tablecolumn2)
(objc:call tableview "addTableColumn:" tablecolumn3)

(objc:call tablecolumn1 "bind:toObject:withKeyPath:options:" "value"  
*arrayController* "arrangedObjects.a" 0)
(objc:call tablecolumn2 "bind:toObject:withKeyPath:options:" "value"  
*arrayController* "arrangedObjects.b" 0)
(objc:call tablecolumn3 "bind:toObject:withKeyPath:options:" "value"  
*arrayController* "arrangedObjects.c" 0)

(objc:call *arrayController* "addObject:" (objc:list->nsdictionary  
'(("a" . "ducks")
                                                                       
("b" . "cats")
                                                                       
("c" . "dogs"))))

(objc:call *arrayController* "addObject:" (objc:list->nsdictionary  
'(("a" . "trumpet")
                                                                       
("b" . "violin")
                                                                       
("c" . "cello"))))

Cheers,
Andrew.

On 24/09/2009, at 9:54 PM, Andreas Körner wrote:

> (This is the first part of the message but I send it later :)
>
> Okay, I've gone crazy and tried to use a NSTablieview for the UI...
>
> took me the half day for trying to get this working...
>
> I just want to use a NSTableview. I've added it to a simple test nib  
> File, let the tag be zero and got the connection to it without  
> problems in Imupromptu.
> Now is the Problem that the hole funny Cocoa Bindings Stuff seems to  
> work with Subclassing and writing your own controller which I can't  
> do in Impromptu.
> So I googled 3 hours for a solution and did't find anything that  
> really helped.
>
> so far I have:
>
> (define *arrayController* (objc:make "NSArrayController" "init"))
> (define *tableView* (objc:call *content-view* "viewWithTag:" 0))
> (define *firstCol* (objc:call (objc:call *tableView* "tableColumns")  
> "objectAtIndex:" 0))
>
> (objc:call *arrayController* "addObject:" (objc:list->nsdictionary  
> (list (cons "song" "Andi"))))
> (objc:call *arrayController* "addObject:" (objc:list->nsdictionary  
> (list (cons "song" "Leon"))))
>
> (objc:call *firstCol* "bind:toObject:withKeyPath:options:" "Value"  
> *arrayController* "arrangedObjects.song" 0)
>
> Problems:
> =============
> * maybe the Dictionary is not KVO compilant?
>
>     binding to a simple text field raises this:
>     (objc:call  *arrayController* "setSelectionIndex:" 0)
>
>     (define *textView* (objc:call *content-view* "viewWithTag:" 1))
>     (objc:call *textView* "bind:toObject:withKeyPath:options:"  
> "Value"  *arrayController* "selected.song" 0)
>
>     :ERROR: [<NSArrayController 0x11c3b90>  
> addObserver:<NSObjectParameterBinder 0x11e8960>  
> forKeyPath:@"selected.song" options:0x0 context:0x11db450] was sent  
> to an object that is not KVC-compliant for the "selected" property.
>
>     Is there a alternative I can use?
>
>
> * Also the Binding for the Column does raise an error
>
>     :ERROR: [<NSTableColumn 0x1714c9c0> valueForUndefinedKey:]: this  
> class is not key value coding-compliant for the key Value.
> 	
>
> Ok, the Problem is more a Cocoa Problem but in "normal" Cocoa you  
> could solve this another way (I have not too much experience with  
> Cocoa, just a little)
> but here I need to use a Dictionary and a NSArrayController, or are  
> there other solutions?
>
> I did just want to write a simple horizontal mixer :(
>
> PS:
> the gui is initialized this way: (thanks to Oscillating Rhythms)
>
> (define p "/Users/andi/Desktop/")
>
> (objc:call "NSBundle"
>             "loadNibFile:externalNameTable:withZone:"
>             (string-append p "test.nib" ) 0 0)
>
>
>     (define *windows* (objc:nsarray->list (objc:call (objc:call  
> "NSApplication" "sharedApplication") "windows")))
>     (print *windows*)
>     (define *window* '())
>
>
>  (for-each (lambda (win)
>                  (let ((title (objc:nsstring->string (objc:call win  
> "title"))))
>                     (if (string? title)
>                     (if (string=? "Fenster" title)
>                         (set! *window* win)))))
>               *windows*)
>
> (define *content-view* (objc:call *window* "contentView"))
> _______________________________________________
> Impromptu mailing list
> Impromptu at lists.moso.com.au
> http://lists.moso.com.au/mailman/listinfo/impromptu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.moso.com.au/pipermail/impromptu/attachments/20090925/44a00d29/attachment-0001.htm 


More information about the Impromptu mailing list