Tooltip for NSTableView

I have a hint:

cellView.textField.toolTip = cellView.textField.stringValue;

It is always displayed, but I need to show a tooltip only if the text is cropped ... How can I do this?

+4
source share
2 answers

I think you can do this by implementing the text field delegation method, controlTextDidEndEditing and checking the text size. I found that the size returned by sizeWithAttributes: does not match the size that I would have expected when filling out the text field, so I just determined the value that I need for the if if expression empirically (in this example, I had the value of the text field value for the property, theText).

-(void)controlTextDidEndEditing:(NSNotification *)obj {
    NSLog(@"%@",NSStringFromRect([obj.object frame]));
    NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSFont systemFontOfSize:13] forKey:@"NSFontAttributeName"];
    NSSize size = [theText sizeWithAttributes:dict];
    NSLog(@"%@",NSStringFromSize(size));
    if (size.width >69) {
        [obj.object setToolTip:theText];
    }
}
0
source

allowsExpansionToolTips YES xib.

enter image description here

0

All Articles