RubyMotion未定义方法`addTarget'用于#<uiroundedrectbutton:0x761fd40> </uiroundedrectbutton:0x761fd40>

时间:2013-04-18 09:00:57

标签: ios rubymotion

我正在关注动画广播的截屏视频: http://motioncasts.tv/start-building-views-in-rubymotion/

还有一些代码:

button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
button.frame = [[15, 300], [280,50]]
button.setTitle("Move to next view", forState: UIControlStateNormal)
button.addTarget(self,
                 action: "moveToChildView:",
                 formControlEvents: UIControlEventTouchUpInside)

哪个应该有效,但在尝试编译时会产生错误:

(main)> 2013-04-18 18:41:06.205 12wbt[76267:c07] home_controller.rb:19:in `viewDidLoad': undefined method `addTarget' for #<UIRoundedRectButton:0x761fd40> (NoMethodError)
    from app_delegate.rb:6:in `application:didFinishLaunchingWithOptions:'
2013-04-18 18:41:06.208 12wbt[76267:c07] *** Terminating app due to uncaught exception 'NoMethodError', reason: 'home_controller.rb:19:in `viewDidLoad': undefined method `addTarget' for #<UIRoundedRectButton:0x761fd40> (NoMethodError)
    from app_delegate.rb:6:in `application:didFinishLaunchingWithOptions:'
'

据我所知,这是截屏视频的确切代码,应该可以无错误地工作。有什么问题?

1 个答案:

答案 0 :(得分:0)

问题解决了。最后一行应为 forControlEvents ,而不是 formControlEvents