I have a problem with NSTextField - that I can't change the text in it (can change it once, in (void)awakeFromNib, but not after that).
I'll give you my header and implementation here:
#import <Cocoa/Cocoa.h>
#import "Employee.h"
@interface EmployeeView : NSViewController {
NSTextField *mikk;
Employee *employee;
}
@property (retain) IBOutlet NSTextField *mikk;
@property (retain) Employee *employee;
- (void)setSelectedEmployee:(Employee*)employeeIn;
@end
#import "EmployeeView.h"
@implementation EmployeeView
@synthesize mikk, employee;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Initialization code here.
}
return self;
}
- (void)setSelectedEmployee:(Employee*)employeeIn
{
employee = employeeIn;
NSLog(@"given employee = %@", employee.fullName);
[mikk setStringValue: @"hi"];
}
-(void)awakeFromNib
{
NSLog(@"i awoke");
[mikk setStringValue:@"hello"];
}
- (void)dealloc
{
[employee release];
[mikk release];
[super dealloc];
}
@end
It may look f-d up, but the main point is that I call the method
- (void)setSelectedEmployee:(Employee*)employeeIn
in my appDelegate and give it the "Employee" that's selected, thus the instance has an employee to work with. I know for sure, it gets the given employee, because NSLog always prints it out correctly.
The NSTextField called "mikk" is correctly linked in IB, cause it sets the labels text to "hello" in the awakeFromNib method. So the main problem is: why I can't set the labels text elsewhere?
I know this looks weird/stupid, but please let me know, if you'd like any more information (also what, if you can be more specific) and suggestions to make this text more readable.
Edit: Looked over the code and left only the "i-think-important-bits" in. Also retained the IBOutlet without any effect on the goal.
view
outlet, too? – user557219NSViewController
(that's using custom class ofEmployeeView
). Should I make anOutlet
for it in code also? – Mikk RätsepNSViewController
already declares aview
outlet, which you’ve said you’ve already connected. (For the record,@
in comments notifies only the first user; in your comment, it notified Caleb but didn’t notify me.) – user557219