0
我剛剛開始使用RubyMotion學習iOS開發,我正在做這個tutorial。這似乎很容易理解,但現在我堅持了這個錯誤,我得到當我運行rake
命令:未定義的方法`initWithNibName'
ColorController.rb:7:in `initWithColor:': undefined method `initWithNibName' for #<ColorController:0x9b4f470> (NoMethodError)
from SearchController.rb:46:in `open_color:'
from Color.rb:35:in `block in find:'
from query.rb:358:in `call_delegator_with_response'
from query.rb:128:in `connectionDidFinishLoading:'
我到哪裏WHEW WELL THAT IS A TON OF CODE NOW ISN'T IT.
是教程頁面上找到的部分和我卡在那裏。目前我的代碼看起來像:
# app_delegate.rb
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@search_controller = SearchController.alloc.initWithNibName(nil, bundle: nil)
@navigation_controller = UINavigationController.alloc.initWithRootViewController(@search_controller)
@window.rootViewController = @navigation_controller
@window.makeKeyAndVisible
true
end
end
# ColorController.rb
class ColorController < UIViewController
attr_accessor :color
def initWithColor(color)
initWithNibName(nil, bunlde: nil)
self.color = color
self
end
def viewDidLoad
super
self.title = self.color.hex
@info_container = UIView.alloc.initWithFrame [[0, 0], [self.view.frame.size.width, 110]]
@info_container.backgroundColor = UIColor.lightGrayColor
self.view.addSubview @info_container
@color_view = UIView.alloc.initWithFrame [[10, 10], [90, 90]]
@color_view.backgroundColor = String.new(self.color.hex).to_color
self.view.addSubview @color_view
@color_label = UILabel.alloc.initWithFrame [[110, 30], [0, 0]]
@color_label.text = self.color.hex
@color_label.sizeToFit
self.view.addSubview @color_label
@text_field = UITextField.alloc.initWithFrame [[110, 60], [100, 26]]
@text_field.placeholder = "tag"
@text_field.textAlignment = UITextAlignmentLeft
@text_field.autocapitalizationType = UITextAutocapitalizationTypeNone
@text_field.borderStyle = UITextBorderStyleRoundedRect
self.view.addSubview @text_field
@add_button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
@add_button.setTitle("Add", forState: UIControlStateNormal)
@add_button.setTitle("Adding", forState: UIControlStateDisabled)
@add_button.setTitleColor(UIColor.lightGrayColor, forState: UIControlStateDisabled)
@add_button.sizeToFit
@add_button.frame = [[@text_field.frame.origin.x + @text_field.frame.size.width + 10, @text_field.frame.origin.y], @add_button.frame.size]
self.view.addSubview(@add_button)
table_frame = [[0, @info_container.frame.size.height], [self.view.bounds.size.width, self.view.bounds.size.height - @info_container.frame.size.height - self.navigationController.navigationBar.frame.size.height]]
@table_view = UITableView.alloc.initWithFrame(table_frame, style: UITableViewStylePlain)
self.view.addSubview(@table_view)
end
end
# SearchController.rb
class SearchController < UIViewController
def viewDidLoad
super
self.title = "Search"
self.view.backgroundColor = UIColor.whiteColor
@text_field = UITextField.alloc.initWithFrame [[10, 10], [self.view.frame.size.width - 20, 30]]
@text_field.placeholder = "#abcabc"
@text_field.textAlignment = UITextAlignmentLeft
@text_field.autocapitalizationType = UITextAutocapitalizationTypeNone
@text_field.borderStyle = UITextBorderStyleRoundedRect
@text_field.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2 - 100)
self.view.addSubview @text_field
@search_button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
@search_button.setTitle("Search", forState: UIControlStateNormal)
@search_button.setTitle("Loading", forState: UIControlStateDisabled)
@search_button.sizeToFit
@search_button.center = CGPointMake(self.view.frame.size.width/2, @text_field.center.y + 40)
self.view.addSubview @search_button
@search_button.when(UIControlEventTouchUpInside) do
@search_button.enabled = false
@text_field.enabled = false
hex = @text_field.text
hex = hex[1..-1] if hex[0] == "#"
Color.find(hex) do |color|
if color.nil?
@search_button.setTitle("None :(", forState: UIControlStateNormal)
else
@search_button.setTitle("Search", forState: UIControlStateNormal)
self.open_color(color)
end
@search_button.enabled = true
@text_field.enabled = true
end
end
end
def open_color(color)
self.navigationController.pushViewController(ColorController.alloc.initWithColor(color), animated: true)
end
end
我也有另外兩個車型,我相信他們是不相關的,除非你要運行的代碼。
有誰能告訴我該怎麼辦?我意識到我正試圖調用initWithNibName
方法,該方法在我的課程中沒有定義,但這是本教程的用法,因此我認爲它是正確的。我需要在ColorController
課上定義它嗎?或者我可以用其他方式調用它?
我是個白癡......這是一些RubyMine的自動完成的,做的是,這不是第一次了。對於支持rubymotion和iOS SDK自動完成的更好的IDE版本,您有任何建議嗎? – Roland
我會用https://github.com/Watson1978/SublimeRubyMotionBuilder推薦崇高的文字。 – rjowens
我有,我真的很喜歡它,我一直在使用它來構建涉及html,js,css的項目,但是rubymine有更多的功能可以幫助...而且我無法讓文件夾留在側欄中我切換到Mac,每當我退出後重新打開它,文件夾都從左側欄(在ST中)消失, – Roland