简体   繁体   English

MacRuby Xcode标签不起作用

[英]MacRuby xcode label not working

class HelloApp
        attr_accessor :label, :text_field, :button
        def clickedButton(sender)
            # implementation
            your_name = self.text_field.stringValue
            self.label.stringValue = "Hello,  #{your_name}"
        end
end

The above code is in HelloApp.rb The problem is when I type something into the textbox, and click the button, the label just says "Hello, " and not "Hello, namegoeshere" I am using MacRuby .4 by the way. 上面的代码在HelloApp.rb中。问题是当我在文本框中键入内容,然后单击按钮时,标签仅显示“ Hello”,而不是“ Hello,namegoeshere”。我正在使用MacRuby .4。

Your code works for me in MacRuby .5 您的代码在MacRuby .5中对我有用

Does this log the user input to the console? 这是否会将用户输入记录到控制台?

your_name = self.text_field.stringValue
puts "Your name is #{your_name}" 

If not, you may not have the text_field hooked up to the NSTextField in Interface Builder. 否则,您可能没有将text_field连接到Interface Builder中的NSTextField。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM