Newbie problem with NSTextField

Joined
Jul 4, 2013
Messages
1
Reaction score
0
Points
1
I am working on my forst Cocoa project and have come up against a strange problem I cannot solve.
This app is a small menu bar application, with a menu and 2 dialogs.
Then the dialogs are shown, some data is displayed, however, for some reason, the NSTextfields, in fact none of the controls are being updated.

The main delegate have this method to show the window:
Code:
-(IBAction)doAdd:(id)sender
{
    if(!vapingController)
    {
        vapingController = [[kp_VapingSpendController alloc] initWithWindowNibName:@"Add Vaping Spend"];
    }
    [vapingController showWindow:self];
}

whilst in the kp_VapingController, I currently have the following code:

Code:
@interface kp_VapingSpendController ()

@end

@implementation kp_VapingSpendController

- (id)initWithWindow:(NSWindow *)window
{
    self = [super initWithWindow:window];
    if (self) {
        // Initialization code here.

    }
    
    return self;
}

- (void)windowDidLoad
{
    [super windowDidLoad];
    
    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    [spent setStringValue:@"0.00"];
    [[self window] setTitle:@"Test"];
}

@end

Neither the NSTextField spent, nor the windows title are being updated.

Any help would be greatly appreciated.
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
Firstly you are initializing the vapingController instance vaiable with the kp_VapingSpendController's
initWithWindowNibName, but you're implementation of the kp_VapingSpendController does not
implement the initWithWindowNibName method, it only shows the initWithWindow method in you're code
snippet.

Secondly you've not shown the public interface for the kp_VapingSpendController class, only the private
interface, so we cant see if you've placed an IBOutlet to the TextField.
Also I suspect you've not set up the window connection in Interface Builder, to you're window controller.

When naming objects like NSTextField's, it's good practice to name them so other programmers can
understand what they are, the name "spent" sounds more like a variable than a UI object, so I would name
you\re textField something like "spentTextField", that way it's more clear to yourself and others what it is.

Check that you have connections to any UI objects that you wish to manipulate, set up in the public
interface as IBOutlet's.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top