Image in NSTableView

Discussion in 'Mac Programming' started by LinusR, Jan 19, 2011.

  1. LinusR macrumors regular

    LinusR

    Joined:
    Jan 3, 2011
    #1
    Good evening,

    I have an NSTableView in my application and I use bindings and a property list file to populate it. My plist-file is in the application main bundle. In my tableview I have code like this to add files to my plist:
    Code:
    - (IBAction)addFileAction:(id)sender {
    	 filePath = [[[NSBundle mainBundle] pathForResource:@"Files" ofType:@"plist"] retain];
             NSDictionary *dict =[NSDictionary dictionaryWithObjectsAndKeys:
                             [tableViewReihe stringValue], @"reiheName",
                             [tableViewTitel stringValue], @"titelName",
                             [tableViewRating stringValue], @"rating",
    			 [tableViewDescription stringValue], @"description",
    			 [audioFilePath stringValue], @"audioPath",     
    			 [coverFilePath stringValue], @"coverPath", 
    			 [hoerspielNummer stringValue], @"number",
                             nil];	
        [arrayFiles addObject:dict];	
        if ( ![[NSFileManager defaultManager] fileExistsAtPath:filePath] || [[NSFileManager defaultManager] isWritableFileAtPath:filePath]) {
            [[arrayFiles arrangedObjects] writeToFile:filePath atomically:YES];
        }
    }
    
    ... and this code to load from plist:
    Code:
    filePath = [[[NSBundle mainBundle] pathForResource:@"Files" ofType:@"plist"] retain];
        cassettes  = [[NSMutableArray alloc] init];
        if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
            NSMutableArray *files = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
            for (id file in cassettesFile) {
                [arrayFiles addObject:file];
            }
        }
    
    Now I want an image in one cell. How can I do this?

    Thanks for any help,

    Linus
     
  2. kainjow, Jan 19, 2011
    Last edited: Jan 19, 2011

    kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Make a new column, set the column's cell to an NSImageCell, and bind your object's image to that column.

    Depending on where your image is coming from, you may want to look into NSValueTransformer. So for example you could bind your entire object for that row to the column, then apply an NSValueTransformer which could examine any part of that object and return an image depending on the data.

    If you want an image with the text in a single cell, look up ImageAndTextCell on developer.apple.com
     
  3. LinusR thread starter macrumors regular

    LinusR

    Joined:
    Jan 3, 2011
    #3
    it works great, thanks for your help. :)

    Have a nice day,

    Linus
     

Share This Page