// Create the text field
NSTextField* textField = [[NSTextField alloc] initWithFrame:NSMakeRect(x, y, width, height)];
// Use the system font using the standard size
textField.font = [NSFont labelFontOfSize:[NSFont systemFontSize]];
textField.textColor = [NSColor textColor];
[textField setStatic];
[textField setID:idControl];
[textField setText:szText]; // <== crash in this function
@implementation NSTextField(NSTextFieldAdditions)
(void) setStatic
{
self.alignment = NSLeftTextAlignment;
self.bordered = NO;
self.drawsBackground = NO;
self.bezeled = NO;
self.editable = NO;
self.selectable = NO;
}
(void) setText:(const tchar*)szText
{
// If an input control then use the unstyled text. If a static control then use the attributed text
if ((self.isEditable) || (self.isSelectable) || (self.drawsBackground)) { // <== Always take this path which should not happen
self.stringValue = [NSString stringWithUTF8String:szText];
} else {
NSMutableAttributedString* attrStringMutable = [[[NSMutableAttributedString alloc] initWithString:nszText attributes:attrDic] autorelease];
self.attributedStringValue = attrStringMutable;
}
Topic:
UI Frameworks
SubTopic:
AppKit