NSMatrix 在 NSTextFieldCell 原型上调用 NSFormCell 的方法



我用NSTextFieldCell作为原型创建了一个NSMatrix。但是当视图被添加到窗口并绘制时,我得到这个错误:

-[NSTextFieldCell setTitleWidth:]: unrecognized selector sent to instance 0x21191040

为什么Cocoa调用setTitleWidth:在一个NSTextFieldCell原型?setTitleWidth:是一个NSFormCell方法,而不是一个NSTextFieldCell方法。

如果我子类化原型,并为setTitleWidth:和titleWidth:添加虚拟方法,一切工作,但这肯定是一个hack。

知道是怎么回事吗?下面是工作代码的相关部分:

(defclass easygui::cocoa-matrix-cell (easygui::cocoa-extension-mixin ns:ns-text-field-cell)
  ((title-width :accessor title-width))
  (:metaclass ns:+ns-object))
(objc:defmethod (#/setTitleWidth: void) ((self easygui::cocoa-matrix-cell) (width :<CGF>LOAT))
  (setf (title-width self) width))
(objc:defmethod (#/titleWidth: :<CGF>LOAT) ((self easygui::cocoa-matrix-cell) (size :<NSS>IZE))
  (title-width self))
(defmethod initialize-instance :after ((view sequence-dialog-item) &key)
  (let ((cocoa-matrix (cocoa-ref view))
        (prototype (#/init (#/alloc easygui::cocoa-matrix-cell))))
    (#/setPrototype: cocoa-matrix prototype)
    (#/setMode: cocoa-matrix #$NSListModeMatrix)
    (#/setIntercellSpacing: cocoa-matrix (ns:make-ns-size 0 0))
    (set-cell-size view (cell-size view))
    (set-table-sequence view (table-sequence view))
    ))

结果是我的NSMatrix对象实际上是NSForm对象。后者继承了前者,但要求以NSFormCell为原型。我试图使用NSForm对象的NSTextFieldCell原型,这就是为什么那些NSFormCell方法仍然被调用。

这里是需要的更改:

-(defclass easygui::cocoa-matrix (easygui::cocoa-extension-mixin ns:ns-form)
+(defclass easygui::cocoa-matrix (easygui::cocoa-extension-mixin ns:ns-matrix)

相关内容

最新更新