1,105,625 Community Members

The label won't change when I press the button.

Member Avatar
pars99
Junior Poster in Training
57 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Everytime I press the button, it's supposed to change the label, but it doesn't. It also doesn't see that I have made any connections. Please help. Thank you in advance.

AppController.m:

#import "AppController.h"

@implementation AppController

-(IBAction)sayHello:(id)sender{
    [label setStringValue:@"Hello World!"];
}

@end

AppController.h:

#import <Foundation/Foundation.h>

@interface AppController : NSObject{
    IBOutlet NSTextField *label;
}

-(IBAction)sayHello:(id)sender;

@end

The window:

Click Here

Member Avatar
ChrisPadgham
Posting Pro in Training
450 posts since Sep 2009
Reputation Points: 113 [?]
Q&As Helped to Solve: 90 [?]
Skill Endorsements: 8 [?]
 
0
 

That is not a label that is a text field. Drag a label across from the object library, it will have type of UILabel. If you are using the latest version of xcode you should be putting an underscore on the front when referrring to them locally,

[_label setText=@"Hello World"];

or

self.label.text = @"Hello World";
Member Avatar
pars99
Junior Poster in Training
57 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

That is not a label that is a text field. Drag a label across from the object library, it will have type of UILabel. If you are using the latest version of xcode you should be putting an underscore on the front when referrring to them locally,

Thank you, but I figured out what was wrong, coincidentally, today. All that was wrong was I had never set AppController.m in the Compile Sources. Thanks though.

Question Answered as of 9 Months Ago by ChrisPadgham
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article