Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

LinusR

macrumors 6502
Original poster
Jan 3, 2011
334
515
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
 
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
 
Last edited:
it works great, thanks for your help. :)

Have a nice day,

Linus
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.