Putting image into tableview cell

Discussion in 'Mac Programming' started by Samppaa, Aug 20, 2010.

  1. Samppaa macrumors regular

    Joined:
    Mar 26, 2010
    #1
    What I basically want to do do is add image into my table cell(At the left) and increase the height of my table cell, so there would be image and text next to it. This might sound dumb, but I actually didn't find a good tutorial which teaches how to do this easily :S Thanks in advance..
     
  2. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #2
    I have done that by subclassing NSTextFieldCell and overriding -drawInteriorWithFrame:inView: , which requires you to do the math and draw the contents appropriately. Of course, your cell does need to be able to obtain the correct image - since it is a custom format, you could do that by passing the table a dictionary or array with both the text and the image. Alternately, you can deliver the image in tableView:willDisplayCell:forColumn:row:

    If your table does not have column-reordering, you could just add a NSImageCell next to the column in question.
     
  3. Samppaa thread starter macrumors regular

    Joined:
    Mar 26, 2010
    #3
    It doesn't have reordering I could use that way, but how can I increase the height of the cell so it fits in correctly?
     
  4. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #4
    You would have to set the row height, which you can do for the whole table in interface builder or programatically, or you can return a variable row height (if there are rows with no image that you want to make smaller, or if you want different sized rows for different images) using a tableview delegate method.
     

Share This Page