【发布时间】:2011-05-28 15:41:53
【问题描述】:
为什么我的代码显示 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);
}
【问题讨论】:
-
您的格式可能不正确,即
nil。试着把它放在NSLog()。 -
appDelegate.times是什么类的实例? -
times是浮点数吗?我注意到您使用了两个不同的NSString占位符。 -
differenceLabel 对象是否连接为 IBOutlet?
-
NSLog 工作正常并返回时间差。但是 --->[differenceLabel setText:[NSString stringWithFormat:@"%@", appDelegate.times]];
标签: iphone objective-c xcode label nslog