Reputation: 75
Why does my code show the NSLog but not change the label text? I'm trying to show the appDelegate.times but it's not working.
-(void)Dothis
{
//retain
appDelegate = [[[UIApplication sharedApplication] delegate] retain];
//display in label
differenceLabel.text = [[NSString alloc] initWithFormat:@"%.3f", appDelegate.times];
//display in console
NSLog(@"Computed time wasrggsdfgd: %@", appDelegate.times);
}
Upvotes: 1
Views: 831
Reputation: 692
You need to do it like this :
[differenceLabel setText:[NSString stringWithFormat:@"%@", appDelegate.times]];
You really don't need to instantiate by a new NSString object by yourself for that... And moreover then you forgot to release your NSString object...
And according to your log , it seems that "appDelegate.times" is actually not a float (%f...)
Upvotes: 1
Reputation: 3657
This should do the trick:
here's my function which sets the label text and it looks like this
-(void)seeValue { appdelegate = (stackoverflowQueriesAppDelegate*)[[UIApplication sharedApplication]delegate]; lbl.text = [NSString stringWithFormat:@"%.f",appdelegate.f]; }
I am assigning a float value as the text of my label lbl and here's a view of the code present inside my appdelegate file
@interface stackoverflowQueriesAppDelegate : NSObject { float f; } @property (nonatomic,assign) float f; @property (nonatomic, retain) IBOutlet UIWindow *window; @end
and here's a view to my appdelegate.m file
@implementation stackoverflowQueriesAppDelegate @synthesize window=_window,f; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. f= 225.32; myview *obj = [[myview alloc]init]; [self.window addSubview:obj.view]; [self.window makeKeyAndVisible]; return YES; }
hope this helps
Upvotes: 0