Ios RubyMoon—未定义的方法`fontWithName';对于UIFont:Class
我在控制器中使用了以下方法,它添加了一个视图标签作为导航标题Ios RubyMoon—未定义的方法`fontWithName';对于UIFont:Class,ios,rubymotion,Ios,Rubymotion,我在控制器中使用了以下方法,它添加了一个视图标签作为导航标题 def viewSetupTitle @titleLabel = UILabel.alloc.initWithFrame([[0, 0], [300, 40]]) @titleLabel.text = "My App" @titleLabel.textColor = UIColor.redColor @titleLabel.backgroundColor = UIColor.clearColor
def viewSetupTitle
@titleLabel = UILabel.alloc.initWithFrame([[0, 0], [300, 40]])
@titleLabel.text = "My App"
@titleLabel.textColor = UIColor.redColor
@titleLabel.backgroundColor = UIColor.clearColor
@titleLabelFont = UIFont.fontWithName("Avenir-Black")
@titleLabel.font = @titleLabelFont
@titleLabel.adjustsFontSizeToFitWidth = true
self.navigationItem.titleView = @titleLabel
end
当我运行rake
时,我得到以下错误:
2014-05-29 10:54:00.519 My App[14839:70b] query_controller.rb:19:in `viewSetupTitle': undefined method `fontWithName' for UIFont:Class (NoMethodError)
from query_controller.rb:8:in `viewDidLoad'
from app_delegate.rb:9:in `application:didFinishLaunchingWithOptions:'
2014-05-29 10:54:00.520 My App[14839:70b] query_controller.rb:19:in `viewSetupTitle': undefined method `fontWithName' for UIFont:Class (NoMethodError)
from query_controller.rb:8:in `viewDidLoad'
from app_delegate.rb:9:in `application:didFinishLaunchingWithOptions:'
2014-05-29 10:54:00.523 My App[14839:70b] *** Terminating app due to uncaught exception 'NoMethodError', reason: 'query_controller.rb:19:in `viewSetupTitle': undefined method `fontWithName' for UIFont:Class (NoMethodError)
from query_controller.rb:8:in `viewDidLoad'
from app_delegate.rb:9:in `application:didFinishLaunchingWithOptions:'
如果调用UIFont类上的fontWithName
、fontName
或任何其他方法,则会出现类似错误
我很困惑,因为如果我在我的代码中运行puts UIFont.instance\u methods.inspect
,我可以看到上面所有的方法(以及根据苹果的文档应该存在的其他方法)
我哪里做错了
谢谢您只是没有添加方法的第二部分(RubyMotion iOS/OS X方法包括看起来像关键字参数或散列选项的内容)。方法的完整名称是
UIFont\fontWithName:size:
您需要添加一个尺寸UIFont.fontWithName(“Avenir Black”,大小:14)
,因为它不是可选参数,而是方法名称的一部分