views:

41

answers:

1

I tried to display imagecells in tableview, but the program crashes..

here's my imageCell class:

@interface ImageCell : NSTextFieldCell {
    NSImage *imageIcon;
    NSString *labelStr;
}
@property (retain) NSImage *imageIcon;
@property (retain) NSString *labelStr;

- (id) initWithLabel:(NSString *) labelString imageName:(NSString *) imageString;

when the program runs, it crashes with error message:

-[NSTextFieldCell labelStr]: unrecognized selector sent to instance 0x10011f160 

but I already provide my own imageCell class...

is there anything I did wrong, thanks!!!

here's my tableview delegate & datasource:

- (void) awakeFromNib {

    self.list = [[NSMutableArray alloc] init];
    [self.list addObject:[[ImageCell alloc] initWithLabel:@"Library" imageName:@"album.tiff"]];

    // set first cell here
    NSTableColumn *col = [[self.tableView tableColumns] objectAtIndex:0];
    [col setDataCell:[list objectAtIndex:0]];
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)pTableView {

    return [self.list count];
}

- (id)tableView:(NSTableView *)pTableView objectValueForTableColumn:(NSTableColumn *)pTableColumn row:(int)pRow {

    ImageCell *imageCell = (ImageCell *)[self.list objectAtIndex:pRow];
    return imageCell.labelStr;
}

- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell 
                                            forTableColumn:(NSTableColumn *)tableColumn 
                                                       row:(NSInteger)pRow {

    ImageCell *imageCell = (ImageCell *)cell;
    imageCell.image = [[self.list objectAtIndex:pRow] imageIcon];
    [imageCell setTitle:imageCell.labelStr];
}
+1  A: 

The docs don't specify any guarantee that the table columns returned by -tableColumns are in any particular order. Try asking for -tableColumnWithIdentifier: (and make sure your table columns have identifiers specified in the nib).

Bored Astronaut
that helps! thanks :D
Frost