0

I have problems for customizing the text in the NSCell for the NSTableView. Below is the main window: enter image description here

The window has a table view which shows an icon, a title,a progress indicator and a message.As my computer is 10.6, I implement it with cell-based tableview. The custom cell is based on the ImageAndTextCell which is provided by the Apple. The message is drawn like:

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSMutableDictionary *fontAttributes = [NSMutableDictionary dictionaryWithCapacity:1];
    [fontAttributes setObject:[NSFont fontWithName:@"Hei" size:12] forKey:NSFontAttributeName];
    if (!self.msg) {
        self.msg = @"default";
    }
    CGRect textFrame = cellFrame;
    textFrame.origin.x += 20;
    textFrame.origin.y += 20;
    [self.msg drawAtPoint:textFrame.origin withAttributes:fontAttributes];
}

msg is a copy NSString property of the cell. I met two problems:

1 when I select one cell, the message will dismissed,just like: enter image description here

Only you unselect it, will it show again. How should I do to fix it?

2 I need to custom the title. As you can see, each cell has a title, sae or IBM. It is the value returned from the delegate:

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex;

Can I change the position, color, or font of it?

scorpiozj
  • 2,687
  • 5
  • 34
  • 60

1 Answers1

0

Try like this and for setting the font you can use setfont api for nscell:-

-(void)awakeFromNib
{
    cellArray=[[NSMutableArray alloc]init];
    NSCell *cell=[[NSCell alloc]initTextCell:@"firstCellValue"];
     NSCell *cell2=[[NSCell alloc]initTextCell:@"secondCellValue"];
    mutableDictionary=[NSMutableDictionary dictionary];
    [mutableDictionary setObject:cell forKey:@"FirstColumn"];
    [mutableDictionary setObject:cell2 forKey:@"secondColumn"];
    [cellArray addObject:mutableDictionary];
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
    return [cellArray count];
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
    if ([[aTableColumn identifier] isEqualToString:@"FirstColumn"])
    {
        NSCell *cell1=[mutableDictionary objectForKey:@"FirstColumn"];
        [aTableColumn setDataCell:cell1];
        return  [cell1 objectValue];
    }
    else if ([[aTableColumn identifier] isEqualToString:@"secondColumn"])
    {
        NSCell *cell2=[mutableDictionary objectForKey:@"secondColumn"];
        [aTableColumn setDataCell:cell2];
        return  [cell2 objectValue];
    }
    else
    {
        return nil;
    }
}
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56