私はプログラムでNSTableViewをセットアップしようとしています(私は本当にIBの使用を避ける必要があります)、そして私が見つけたすべての例は、インターフェース構築を使用してこれを行う方法を説明しています。tableView:objectValueForTableColumn:row:メソッドとnumberOfRowsInTableView:メソッドを実装するコントローラークラスを作成しましたが、呼び出されることはありません。
テーブルビューとスクロールビューを設定した後、numberOfRowsInTableView:を実装したコントローラークラスを使用してsetDelegate:とsetDataSource:を呼び出しました。残念ながら、コードを実行すると、numberOfRowsInTableView:またはtableView:objectValueForTableColumn:row:が呼び出されることはありません。私がやろうとしていることを達成するために、setDelegate:とsetDataSource:以外の何かを呼び出す必要がありますか?
私はこのコードをclozure-cl(cocoa-lispブリッジを含むlisp環境)で書いています。ここのほとんどのcocoa開発者は、lisp愛好家ではない可能性が高いと思います。そのため、コードを投稿することは有益ではないようですが、誰かが私にくれれば素晴らしいIBを使用せずにこのプロセス全体を実行するobjective-cコードへの提案またはリンク。
編集:
これが私のlispコードの一部です。lisp以外のココア開発者にとってより明確にするためにコメントを追加してみます。
(defmethod DISPLAY-TABLE-VIEW ((Self table-view))
(with-simple-restart (cancel-pop "Stop trying to pop up ~s" Self)
(in-main-thread ()
(ccl::with-autorelease-pool
;let statements are just declarations of local variables in lisp
;this one just creates the window I want to put the table-view inside
(let ((Window (make-instance 'popup-window
:lui-window Self
:with-content-rect (ns:make-ns-rect (x self) (y self) (width Self) 500 )
:style-mask 3
:backing #$NSBackingStoreBuffered
:defer t)))
(setf (native-window Self) Window) ;; need to have this reference for the delegate to be in place
(setf (native-view Self) (make-instance 'popup-window-view :lui-window Self ))
;; setup delegate
(setf (delegate Window) (make-instance 'popup-delegate :lui-window Self))
(#/setDelegate: Window (delegate Window))
; (#/setStyleMask: Window 1)
;here I create first a table-view then a scroll-view the an NSView and
;finally a column
(let ((table-view (#/alloc ns:ns-outline-view)))
(let ((scroll-view (#/alloc ns:ns-scroll-view)))
(let ((content-view (#/alloc ns:ns-view)))
(let ((column (#/alloc ns:ns-table-column)))
(setf content-view (#/contentView Window))
(ns:with-ns-rect (Frame 0 0 100 100)
;here we initialize the table-view the scroll-view and column then
;add the column
(#/init table-view)
(#/initWithFrame: scroll-view (#/frame (#/contentView Window)))
(#/initWithIdentifier: column (native-string "0"))
(#/addTableColumn: table-view column)
;make an instance of my controller class which is an nsObject
;I also tried to make it an NSWindowController but that didn't help
(let ((package-view (make-instance 'table-view-controller)))
;set the data source and the delegate
(#/setDataSource: table-view package-view)
(#/setDelegate: table-view package-view)))
(#/setHasVerticalScroller: scroll-view #$YES)
(#/setDocumentView: scroll-view table-view)
(#/setAutoresizesSubviews: (#/contentView Window) #$YES)
(#/addSubview: (#/contentView Window) scroll-view))))
(#/reloadData: table-view))
(#/setHasShadow: Window #$YES)
;display the window
(#/makeKeyAndOrderFront: Window Window))))))
これが私のnumberOfRowsInTableViewからのスニペットです:私のコントローラーtable-view-controllerの一部であるメソッド(この呼び出しはNSObjectのです)。
(objc:defmethod (#/numberOfRowsInTableView: #>NSInteger)
((self table-view-controller) (tab :id))
(print "hello")
;;... then do other things but just seeing the print statement would be a great step