0

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?

jscs
  • 63,694
  • 13
  • 151
  • 195
Amitg2k12
  • 3,765
  • 10
  • 48
  • 97

1 Answers1

1

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.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • Thanks peter , let me try with delegate, actually i am searching for all possible delegate function, i could able to display transparent background and text along with two colo, but i don't know how to display an image in one col. – Amitg2k12 Jan 20 '11 at 15:22
  • As I said, you need to put an image cell in that column. See the IB User Guide. The data source and delegate methods are all listed in the documentation for those protocols. – Peter Hosey Jan 20 '11 at 15:28
  • Hello Peter, i am newbie in Cocoa, So far i have done following, – Amitg2k12 Jan 21 '11 at 07:30