Cocoa help thread

Associate
Joined
9 Jun 2009
Posts
1,397
Location
Suffolk
Thanks to you all for the suggestions for cocoa books, I've been trying to get my first simple app working, where I am breaking apart a JSON feed in order to print some information to the screen, now I'm getting stuck with this code and I can't for the life of me work out whats wrong:

Code:
...
@property (strong, nonatomic) NSString *serverName;
@property (strong, nonatomic) NSNumber *serverPop;
@property (strong, nonatomic) NSNumber *serverPatch;

@end

@implementation ncStatsViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    ncStats *feed = [[ncStats alloc]init];
    [feed getStatus];
    _serverName = feed.serverName;
    _serverPop = feed.population;
    _serverPatch = feed.patch;
    
}

- (IBAction)changeGreeting:(id)sender {
    self.serverLabel.text = _serverName;
    self.popLabel.text = _serverPop;
    self.patchLabel.text = _serverPatch;
}
...

the serverLabel, popLabel and patchLabel are linked to labels in the UI that I am trying to update with the information from the feed of serverName, population and patch.

Any help to fix this would be appreciated!

TIA
 
Associate
Joined
15 Oct 2009
Posts
579
Are you making sure that the properties in the feed object are being populated? If they aren't your just assigning nil to the NSString properties of your class which is why when you assign their values to the text properties of the labels nothing is being shown. Place a brake point or use NSLog(@"%@", self.serverName); for example.

Also using the latest versions of Xcode you should move away from accessing a property by it's _name, you should be calling self.propertyName to go through the getter and setter methods unless you really have a reason to access the property directly.

If you are finding that the feed properties are being assigned correctly you should probably make sure that your labels are linked to your xib/storyboard correctly and your IBAction is being called correctly from your button.
 
Back
Top Bottom