Question

I created an NSMatrix with an NSTextFieldCell as its prototype. But when the view is added to a window and drawn, I get this error:

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

Why is Cocoa calling setTitleWidth: on an NSTextFieldCell prototype? setTitleWidth: is an NSFormCell method, not an NSTextFieldCell method.

If I subclass that prototype and add dummy methods for setTitleWidth: and titleWidth:, everything works, but this is surely a hack.

Any ideas what's going on? Below is the relevant section of the working code:

(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))
    ))
Was it helpful?

Solution

It turned out that my NSMatrix object was actually an NSForm object. The latter inherits from the former, but requires that it uses an NSFormCell as its prototype. I was trying to use an NSTextFieldCell prototype for an NSForm object, which was why those NSFormCell methods were still being called.

Here was the needed change:

-(defclass easygui::cocoa-matrix (easygui::cocoa-extension-mixin ns:ns-form)
+(defclass easygui::cocoa-matrix (easygui::cocoa-extension-mixin ns:ns-matrix)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top