【问题标题】:Assigning the text label from a UIButton to a UILabel not working将文本标签从 UIButton 分配给 UILabel 不起作用
【发布时间】:2011-01-23 19:32:00
【问题描述】:

我在 .h 中声明了这个

IBOutlet UILabel *display;

在 .m 中,我正在执行以下操作,但它不起作用,一直说 displat.text 为空。困惑,求助!是的,我是菜鸟。

NSLog(@"operation button pressed %@ is of class %@",[[sender titleLabel] text],[[[sender titleLabel] text] class] ); 
NSString *operation = [[sender titleLabel] text];
[display setText:operation];
NSLog(@"display text is of class %@ and equals %@",[display.text class], [display text]);

我也试过这样:

NSLog(@"digit button pressed %@ is of class %@",[sender currentTitle],[[sender currentTitle] class] );
display.text = (NSString *)[[sender titleLabel] text];
NSLog(@"display text is of class %@ and equals %@",[display.text class], [display text]);

【问题讨论】:

  • 你有 NSLog() 语句散布在这里和那里......你的运行日志中的输出是什么?

标签: iphone cocoa uibutton uilabel


【解决方案1】:

要检查两件事:

  1. 确保您的“显示”插座已在 Interface Builder 中连接。
  2. 在调用此代码之前,请确保您的界面已完全加载。

关于第 2 项,如果您让我们知道从哪里调用此问题代码(从什么方法),给您建议会更容易。它是一个动作还是在启动时?在哪里?

【讨论】:

  • 它是一个动作。我有计算器按钮(操作和数字)作为 IBActions 并显示为 IBOoutlet。我正在尝试从按钮读取标签并将其分配给 display.text 以显示它。
  • 好的...插座连接了吗?日志语句的输出是什么?如果您没有发布足够的信息,我们将无法帮助您。
  • 知道了!你确实帮助了我。我在 UILabel 和连接不正确之间搞砸了!现在工作!!!谢谢!
  • 始终先检查您的网点。他们通常是你忘记的第一件事。 :-)
猜你喜欢
  • 2016-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-04
相关资源
最近更新 更多