Question

I want to customize my NSTableView. My overall requirements are like this:

  • Each row will have one image and some text; images and text could be different.
  • Some cells might not have an image.
  • Row height is dependent upon some external factor.
  • A cell shouldn't draw the background, it should show the NSTableView background.

So far I am able to draw transparent cells with some text. I Googled and found out I need to customize each cell. Now I have this question: should I maintain two columns or should one column be okay, having one image on the left hand side and text adjacent to that?

I also understand that I need to override two methods:

- (void) drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

So for each cell, I need to draw/construct the cell -- can anyone guide me? Am I going in the right direction? Can I achieve a transparent background with dynamic height with the above approach?

Was it helpful?

Solution

Each row will have one image and some text,

So, two columns—one with an image cell, the other with a text field cell.

images and text could be different,

I should hope so.

Some cell might not have the Image,

Not a problem.

Row height is depend upon some external factor,

Be the table view's delegate, and it will ask you what the row's height should be.

Cell shouldn't draw the background,

It won't unless you set it to do so.

it should overall it should show the NSTableView background,

The table view will draw its own background anyway, which you can set in IB's Inspector. If you wanted the table view to not draw a background, you would set its background colors to the clear color.

You don't need a custom cell for any of this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top