Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios RubyMoon—未定义的方法`fontWithName';对于UIFont:Class_Ios_Rubymotion - Fatal编程技术网

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)
,因为它不是可选参数,而是方法名称的一部分