为什么我的代码显示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);
}
    

解决方法

        您需要这样做:
[differenceLabel setText:[NSString stringWithFormat:@\"%@\",appDelegate.times]];
您确实不需要为此单独实例化一个新的NSString对象。此外,您还忘记了释放NSString对象。 并且根据您的日志,看来\“ appDelegate.times \”实际上不是浮点数(%f ...)     ,        这应该可以解决问题: 这是我的功能,它设置标签文本,看起来像这样 -(无效)seeValue { appdelegate =(stackoverflowQueriesAppDelegate *)[[UIApplication sharedApplication] delegate]; lbl.text = [NSString stringWithFormat:@ \“%。f \”,appdelegate.f]; } 我将浮点值分配为标签lbl的文本,这是我的appdelegate文件中存在的代码的视图 @interface stackoverflowQueriesAppDelegate:NSObject {     浮动f; } @property(nonatomic,assign)float f; @属性(非原子的,保留)IBOutlet UIWindow *窗口; @结束 这是我的appdelegate.m文件的视图 @implementation stackoverflowQueriesAppDelegate @synthesize window = _window,f; -(BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     //应用程序启动后进行自定义的替代点。     f = 225.32;     myview * obj = [[myview alloc] init];     [self.window addSubview:obj.view];     [self.window makeKeyAndVisible];     返回是; } 希望这可以帮助     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...