【发布时间】:2013-12-13 21:10:44
【问题描述】:
我刚开始学习 ruby 运动,在教程开始时遇到了障碍!教程是“RubyMotion iOS 开发要点”。
这是我的代码:
class RootController < UIViewController
def viewDidLoad
alert = UIAlertView.alloc.initWithTitle "This is foo title",
message:"Do you like this example?",
delegate: nil,
cancelButtonTitles: "cancel",
otherButtonTitles: "Yes", "No", nil
alert.show
end
end
我知道缩进看起来很有趣,但显然那是 RubyMotion 语法……很奇怪,我知道。 这是我收到的关于“initWithTitle”方法的错误:
(main)> 2013-12-13 00:44:40.780 HelloWorld[97435:80b] root_controller.rb:7:in `viewDidLoad': undefined method `initWithTitle' for #<UIAlertView:0x8d2bcf0> (NoMethodError)
from app_delegate.rb:6:in `application:didFinishLaunchingWithOptions:'
2013-12-13 00:44:40.782 HelloWorld[97435:80b] root_controller.rb:7:in `viewDidLoad': undefined method `initWithTitle' for #<UIAlertView:0x8d2bcf0> (NoMethodError)
from app_delegate.rb:6:in `application:didFinishLaunchingWithOptions:'
2013-12-13 00:44:40.784 HelloWorld[97435:80b] *** Terminating app due to uncaught exception 'NoMethodError', reason: 'root_controller.rb:7:in `viewDidLoad': undefined method `initWithTitle' for #<UIAlertView:0x8d2bcf0> (NoMethodError)
from app_delegate.rb:6:in `application:didFinishLaunchingWithOptions:'
'
我会很感激任何指点,这么早被卡住真是太可惜了!
【问题讨论】:
-
RubyMotion 是一个工具链,可让您使用 RUBY 进行开发,因此您缩进代码(Ruby 代码)的方式不是正确的方式(通常且更易读的方式)。看到跟踪,您似乎缺少方法
initWithTitle的定义。试试p UIAlertView.alloc.methods看看它是否已经用另一个名字定义了。 -
@kira, 方法已经定义 initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:
标签: ios ruby-on-rails ruby rubymotion