Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 以编程方式设置NSTableView(捕获tableView:objectValueForTableColumn:row:)_Cocoa_Macos_Nstableview - Fatal编程技术网

Cocoa 以编程方式设置NSTableView(捕获tableView:objectValueForTableColumn:row:)

Cocoa 以编程方式设置NSTableView(捕获tableView:objectValueForTableColumn:row:),cocoa,macos,nstableview,Cocoa,Macos,Nstableview,我正在尝试以编程方式设置NSTableView(我确实需要避免使用IB),我找到的所有示例都解释了如何使用接口构建来实现这一点。我创建了一个控制器类,该类实现了tableView:objectValueForTableColumn:row:和numberOfRowsInTableView:方法,但它们从未被调用。 设置表视图和滚动视图后,我使用实现numberOfRowsInTableView:的控制器类调用了setDelegate:和setDataSource:。不幸的是,当我运行代码时,它从

我正在尝试以编程方式设置NSTableView(我确实需要避免使用IB),我找到的所有示例都解释了如何使用接口构建来实现这一点。我创建了一个控制器类,该类实现了tableView:objectValueForTableColumn:row:和numberOfRowsInTableView:方法,但它们从未被调用。
设置表视图和滚动视图后,我使用实现numberOfRowsInTableView:的控制器类调用了setDelegate:和setDataSource:。不幸的是,当我运行代码时,它从未调用numberOfRowsInTableView:或tableView:objectValueForTableColumn:行:。我是否需要调用setDelegate:和setDataSource:之外的东西来完成我要做的事情?
我正在clozure cl(一个包含cocoa lisp桥的lisp环境)中编写这段代码我相信这里的大多数cocoa开发人员不太可能是lisp爱好者,所以发布我的代码似乎不会有什么收获,但是如果有人能给我任何建议或链接到objective-c代码,它可以完成整个过程而不使用IB,那就太好了

编辑:

下面是我的一段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:方法中的一个snipet,它是我的控制器表视图控制器的一部分(此调用是NSObject的一个调用)

永远不要向NSView类的实例发送
init
。始终使用
initWithFrame:


永远不要向NSView类的实例发送
init
。始终使用
initWithFrame:

到底什么不起作用?您的数据源方法是否未被调用?是否向表视图中添加了任何
NSTableColumn
?如果以编程方式创建
NSTableView
,默认情况下将不会有任何表列。您还需要创建和添加它们。是的,我添加了一个NsTableColumn,是的,数据源方法没有被调用(我为每个方法添加了一个print语句以确保)。
setDelegate:
setDataSource:
应该足够了。cocoa lisp桥是否正确处理非对象数据?在调用委托对象之前,表视图将检查委托对象是否具有委托方法,因此调试它的一种方法可能是重写
respondsToSelector:
,并查看是否调用了它。屏幕上是否显示滚动视图(及其表视图)?也就是说,它是否位于按顺序排列的窗口的视图层次结构中?如果是这样,如果向表视图发送
reloadData
消息,会发生什么情况?这应该是不必要的,但你不妨检查一下。您是如何创建表视图的?您应该在这一个上显示您的代码,即使它是在Lisp中。是的,我创建了一个带有滚动视图的表视图。当我加载窗口时,我得到一个窗口,其中有一个空表字段,只有标题。此外,该窗口还有一个垂直滚动条。接下来我将发布一些lisp代码。我也尝试过重新加载数据,但这些方法仍然没有被调用。到底是什么不起作用?您的数据源方法是否未被调用?是否向表视图中添加了任何
NSTableColumn
?如果以编程方式创建
NSTableView
,默认情况下将不会有任何表列。您还需要创建和添加它们。是的,我添加了一个NsTableColumn,是的,数据源方法没有被调用(我为每个方法添加了一个print语句以确保)。
setDelegate:
setDataSource:
应该足够了。cocoa lisp桥是否正确处理非对象数据?在调用委托对象之前,表视图将检查委托对象是否具有委托方法,因此调试它的一种方法可能是重写
respondsToSelector:
,并查看是否调用了它。屏幕上是否显示滚动视图(及其表视图)?也就是说,它是否位于按顺序排列的窗口的视图层次结构中?如果是这样,如果向表视图发送
reloadData
消息,会发生什么情况?这应该是不必要的,但你不妨检查一下。您是如何创建表视图的?您应该在这一个上显示您的代码,即使它是在Lisp中。是的,我创建了一个带有滚动视图的表视图。当我加载窗口时,我得到一个窗口,其中有一个空表字段,只有标题。此外,该窗口还有一个垂直滚动条。接下来我将发布一些lisp代码。我还尝试重新加载数据,但这些方法仍然没有被调用。
(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
    (let ((table-view (#/alloc ns:ns-outline-view)))
              (#/init table-view)