Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[__NSCFConstantString pointSize]: unrecognized selector sent to instanc

I am trying to put a Attributed string inside a NSTextField, which itself is inside an NSAlert Here is my code:

NSTextField *label1 = [[NSTextField alloc]initWithFrame:NSMakeRect(0, 23, 50, 20)];
[label1 setEditable:FALSE];
[label1 setAllowsEditingTextAttributes:TRUE];
[label1 setBezeled:FALSE];
label1.backgroundColor = [NSColor clearColor];
NSString *login = @"Username";
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:login];
NSString *boldFontName = [[NSFont boldSystemFontOfSize:12] fontName];
[attrString beginEditing];
NSRange ran = NSMakeRange(0, 8);
[attrString addAttribute:NSFontAttributeName
                   value:boldFontName
                   range:ran];

[attrString endEditing];
NSLog(@"%@",attrString);
[label1 setAttributedStringValue:attrString];
[alert setAccessoryView:label1];
[alert runModal];

However, as soon as [alert runModal] is called, my app crashes

"[__NSCFConstantString pointSize]: unrecognized selector sent to instance 0x7fff74035bb0"

I'm not sure why this is happening. It appears that it is related to the string, because as soon as i remove [alert setAccessoryView:label1] or give label1 a standard nsstring it works fine. Please help!

like image 935
benjih555 Avatar asked Dec 22 '12 08:12

benjih555


1 Answers

You have done right. But you did a small mistake. You have passed NSString as an attribute for NSFontAttributeName but it expects NSFont.

Try this.

    NSFont *boldFontName = [NSFont boldSystemFontOfSize:12];
[attrString beginEditing];
NSRange ran = NSMakeRange(0, 8);
[attrString addAttribute:NSFontAttributeName
                   value:boldFontName
                   range:ran];
like image 136
Ramaraj T Avatar answered Oct 04 '22 10:10

Ramaraj T