Sharing the code snippet. As per the following code, -setText should not set property self.stringValue. Instead it should set self.attributedStringValue. But the crash log we see that crash occurs inside call to setStringValue
// 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];
@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
{
LFTRACE("Text:", 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)) {
self.stringValue = [NSString stringWithUTF8String:szText];
} else {
NSMutableAttributedString* attrStringMutable = [[[NSMutableAttributedString alloc] initWithString:nszText attributes:attrDic] autorelease];
self.attributedStringValue = attrStringMutable;
}
Topic:
UI Frameworks
SubTopic:
AppKit