【问题标题】:Android developer converting to iOS: How to reference UILabel and change the textAndroid 开发者转 iOS:如何引用 UILabel 并更改文本
【发布时间】:2013-12-28 22:05:37
【问题描述】:

我开发了一些Android 应用程序,但最近我一直在寻找开发一些iOS 应用程序。在阅读了几篇tutorials 之后,我尝试制作一个非常基本的应用程序,看看我是否理解。

我有一个UILabel 和两个UIButtons。一个UIButton 增加一个NSInteger 变量,另一个UIButton 减少相同的整数。我的想法是使用UILabel 显示这个整数。

为了让Android 应用程序访问等效类型的结构并更改文本,我将使用以下代码:

TextView my_label = (TextView) findViewById(R.id.my_label);
my_label.setText(""+integer_i_want_to_display);

基本上我想知道上面Android 代码的iOS 等效项。我正在使用SDK 7.0Xcode 5.0.2

【问题讨论】:

  • 寻找stringWithFormat
  • 没有作业,没有帮助......

标签: ios iphone objective-c uilabel


【解决方案1】:

如果您有 UIViewController,您可以在 .h 文件中定义 IBOutlet 并将其连接到 .xib 文件中的 UILabel。例如所以: .h 文件:

@interface MyController : UIViewController {
    IBOutlet UILabel *myLabel;
    NSInteger integer_i_want_to_display;
}

.m 文件:

- (void)someAction {
    myLabel.text = [NSString stringWithFormat: @"%d", integer_i_want_to_display];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多