我刚刚开始学习红宝石运动,在一个教程的开始,我遇到了一个路障!本教程是"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:'‘
我很感激你的指点,这么早就被困在这里真是太令人沮丧了!
发布于 2013-12-13 22:36:20
cancelButtonTitles应该是单数:cancelButtonTitle。
因为你使用复数的措辞,所以它找不到匹配的方法签名。
https://stackoverflow.com/questions/20576045
复制相似问题