【问题标题】:How can I display the current value of an integer on the screen of my app? [closed]如何在我的应用程序屏幕上显示整数的当前值? [关闭]
【发布时间】:2013-01-26 20:26:34
【问题描述】:

我的 AppDelegate.mm 文件中有一个整数 y,我想在我的 iphone 应用程序(xib 文件)的屏幕上显示它。 y 值的范围从 0 到 1024,并且不断变化,因为它反映了进入手机麦克风端口的频率。有没有一种简单的方法可以像显示器一样在应用程序屏幕上显示 y 的当前值?非常感谢您的参与, 蒂莫西·洛瑞

【问题讨论】:

  • 在你的 UI 中添加一个 UILabel。

标签: iphone ios


【解决方案1】:

你可以使用 NSTimer。

计时器使用定期调用该方法,您更新的值将在 uilabel 中反映/更改。

编辑:按照 h2co3 的建议

如果应用程序使用音频数据,几乎可以肯定它有一个为此指定的回调函数 - 应该真正使用该回调而不是计时器。

【讨论】:

  • 合理的解决方案 (+1),但是您可以补充说,如果应用程序使用音频数据,几乎可以肯定它有一个为此指定的回调函数 - 应该真正使用该回调而不是计时器。
【解决方案2】:

您可以声明一个 UILabel 并将其添加到您的视图中,并使用转换为 NSString 的整数。 不过,您将需要一个视图控制器来执行此操作。

       int yourInt;
       NSString *num = [NSString strinWithFormat:@"%d", youInt];
       UILabel *lab = [UILabel alloc] initWhithFrame:CGRectMake(200, 200, 100, 30)];
       lab.text = num;
       [self.view addSubView:lab];

代码未经测试,我只是将其直接写到解决方案框中。

【讨论】:

    【解决方案3】:

    你想在 xib 中显示 Appdelegate 整数 y 的值

    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    lbl.text = [NSString strinWithFormat:@"%d",appDelegate.y];
    

    确保您的 y 整数设置为 AppDelegate 中的属性

    希望对你有所帮助..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      • 2012-07-24
      相关资源
      最近更新 更多