Pages

Saturday, August 17, 2013

NSTextfield setStringValue will not change label text.


Hello All,



I am about to my wits end on this particular issue that I am expierencing. I am unable to set the title of a simple label. I have tried all sorts of things like [self.property setStringValue:@"test"] and not even that will work in changing the labels. I've followed countless tutorials and other online references and they all appear to done this the exact same as I have... I would greatly appreciate recieving a little help in figuring out why it's happening and how it should be fixed properly. The easiest way to show what I have so far will be via screenshots and code examples.



xib file and containing outlets of the labels in question. This is to show that the labels are propperly hooked up as IBOutlets




Here is the relevant code. This is what is called in AppDelegate so you know where to start reading in the code:


   


-(void)applicationDidFinishLaunching:(NSNotification *)aNotification{


     RamdiskSize *caller =[[RamdiskSize alloc]init];


     [caller changeSizeLabels];


}





And here is the results, as you can see the placeholder strings are still in place and were not affected by the setStringValue methods.







And I will include all related code below:




AppDelegate.m:

@implementation AppDelegate- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{        RamdiskSize *caller =[[RamdiskSize alloc]init];    [caller changeSizeLabels];}@end


RamdiskSize.h:

#import #import "MemoryMonitoring.h"@interface RamdiskSize : NSObject@property (weak) IBOutlet NSTextField *minSizeLabel;@property (weak) IBOutlet NSTextField *halfSizeLabel;@property (weak) IBOutlet NSTextField *maxSizeLabel;  -(void)changeTextLabel:(NSTextField *)whichlabel sizeLabel:(NSString *)labelText;-(NSArray *)defineSizeValueLabels;-(void)changeSizeLabels;@end



RamdiskSize.m

#import "RamdiskSize.h"@implementation RamdiskSize@synthesize maxSizeLabel, minSizeLabel, halfSizeLabel;-(void)changeTextLabel:(NSTextField *)whichlabel sizeLabel:(NSString *)labelText{    [whichlabel setStringValue:labelText]; }//  Get Physical memory in MB-(NSArray *)defineSizeValueLabels{    MemoryMonitoring *physicalMemoryObj = [[MemoryMonitoring alloc]init];    unsigned long long physicalMemoryValue = [physicalMemoryObj getPhysicalMemoryValue];    float maxSize = (((float)physicalMemoryValue/1024)/1);    float halfSize = (((float)physicalMemoryValue/1024)/2);    float minSize = ((((float)physicalMemoryValue/1024)/((float)physicalMemoryValue/1024))/2);        return [[NSArray alloc] initWithObjects:[NSNumber numberWithFloat:minSize],[NSNumber numberWithFloat:halfSize],[NSNumber numberWithFloat:maxSize], nil];  }  -(void)changeSizeLabels{    NSArray *sizeArray = [NSArray arrayWithArray:[self defineSizeValueLabels]];    [maxSizeLabel setStringValue:[NSString stringWithFormat:@"%.f GB",[[sizeArray objectAtIndex:2] floatValue]]];    [halfSizeLabel setStringValue:[NSString stringWithFormat:@"%.f GB",[[sizeArray objectAtIndex:1] floatValue]]];    [minSizeLabel setStringValue:[NSString stringWithFormat:@"%.1f GB",[[sizeArray objectAtIndex:0] floatValue]]];}@end

View the original article here

0 comments:

Post a Comment