0

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))
    ))
Clayton Stanley
  • 7,513
  • 9
  • 32
  • 46
  • Is there a specific reason why you chose to define your cell class in the easygui package? I wouldn't do that if possible. Also remember easygui is still young, and that the call to `-[setTitleWidth:]` may be hard coded in easygui. The only way to see if your design works is by throwing a quick Xcode project. – tuscland May 24 '13 at 07:19
  • I may have to load up Xcode to get to the bottom of this. No hard-coded `setTitleWidth:` methods in easygui though, and nowhere suspicious in the CCL src. – Clayton Stanley May 24 '13 at 07:32

1 Answers1

0

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)
Clayton Stanley
  • 7,513
  • 9
  • 32
  • 46