为什么我的代码显示 NSLog 但不更改标签文本?
为什么我的代码显示 NSLog 但不更改标签文本? 我试图显示 appDelegate.times 但它不起作用。
-(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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要这样做:
你真的不需要自己实例化一个新的 NSString 对象......而且你忘记释放你的 NSString 对象......
并且根据你的日志,似乎“appDelegate.times”实际上不是浮点数(%f...)
You need to do it like this :
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...)
这应该可以解决问题:
这是我设置标签文本的函数,看起来像这样,
我分配一个浮点值作为标签 lbl 的文本,这是我的 appdelegate 文件中存在的代码的视图
,这是我的appdelegate.m 文件
希望这有帮助
This should do the trick:
here's my function which sets the label text and it looks like this
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
and here's a view to my appdelegate.m file
hope this helps