Wukerplank
Wukerplank

Reputation: 4176

How do I write a custom control with `NSControl` and `NSActionCell`

I'm looking for a minimal viable example here. I've been googleing and reading up for days now and I can't find a single resource that is up to date.

My NSControl works ok, but as soon as I add

+ (Class)cellClass {
    return [MYCustomCell class];
}

to it I get this output and my window stops to draw properly

<Error>: kCGErrorFailure: CGSShapeWindow
<Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
_NXPlaceWindow: error setting window shape (1000)
<Error>: kCGErrorFailure: CGSShapeWindow
_NSShapeRoundedWindowWithWeighting: error setting window shape (1000)

I've read everything I could find about this subject (including the Apple docs), but everything seems far to vague to come to a proper implementation. I would really appreciate it if somebody could point me in the right direction (proper code example or article).

Upvotes: 1

Views: 835

Answers (1)

macawm
macawm

Reputation: 142

I believe I have finally found the answer.

The -cellSize method must be overridden in your NSCell/NSActionCell subclass. After gobs of stack tracing I discovered that this method will return (40000, 40000) as your cell size if it is not overridden thus creating the sizing errors that we have seen. Since I have special needs in my NSActionCell subclass that require the cell to occupy the entire NSControl's drawing area I simply used the following.

- (NSSize)cellSize {
    return self.controlView.bounds.size;
}

Hope this helps your situation.

Upvotes: 4

Related Questions