Drawing NSImage in NSCell to make it spiffy!

Discussion in 'Mac Programming' started by Littleodie914, Jun 14, 2007.

  1. Littleodie914 macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #1
    Hey guys, I'm trying to draw an NSImage in a NSCell using an NSTableView delegate method.

    Here's what I'm trying:

    Code:
    - (void)tableView:(NSTableView *)tableView 
      willDisplayCell:(id)cell
       forTableColumn:(NSTableColumn *)column 
    			  row:(int)row
    {
    	NSSize mySize;
    	mySize.width = 32;
    	mySize.height = 32;
    	NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[[[filesController arrangedObjects] objectAtIndex:row] valueForKey:@"filePath"]];
    	[icon setSize:mySize];
    	
    	[cell initImageCell:icon];
    	[cell updateCell:cell];
    	[tableView reloadData];
    	
    }
    I also am using the (float)tableView:(NSTableView *)tableView heightOfRow:(int)row method, which works fine, but I can't figure out why the image won't draw. It places an object in the table, and it responds to double-clicks as my text objects do, but nothing is actually drawn, it's just a blank selectable space. Any pointers? Thanks! :D
     
  2. Littleodie914 thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #2
    And as an added bonus, I seem to have "lost" my menu. :(

    The main menu bar, where you change things from NewApplication to <name of application>, seems to have gone missing. It doesn't show up in IB, and there's no instance of it in the Instances window. (I don't remember if there should be or not, but mine has disappeared either way!) Anyone know how to get it back? :eek:


    Edit: Scratch that, forgot that in a Document-based app, the MainMenu is changed in MainMenu.nib, while GUI work happens in MyDocument.nib :eek:
     
  3. HungrySeacow macrumors regular

    Joined:
    Jan 11, 2006
    Location:
    West Palm Beach
    #3
    Look for Apples ImageAndTextCell.h class in your examples folder or online. It is a great subclass to start from.
     
  4. Littleodie914 thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #4
    Thanks a lot for the idea, I'll check it out. Seems like there would be an easier way though, than having to subclass the entire thing and add a bunch of methods. :confused:

    Edit: Got it working, and once the tedious linking and what-not is out of the way, it's actually not too bad :) Thanks a lot for the link!
     

Share This Page