2014-02-13 4 views
0

는 다음과 같은 오류 유무 :RubyMotion : '이름 오류'

Terminating app due to uncaught exception 'NameError', reason: 'weather_controller.rb:3:in `viewDidLoad': uninitialized constant WeatherController::Name (NameError) 

AppDelegate에 :

class AppDelegate 

def application(application, didFinishLaunchingWithOptions:launchOptions) 

    puts "Hello! You just launched: #{App.name}, \n location: (#{App.documents_path})" 
    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) 

    @window.backgroundColor = UIColor.lightGrayColor 
    @window.rootViewController = MyController.alloc.init 
    @window.makeKeyAndVisible 

    true 
end 
end 

my_controller.rb :

class MyController < UIViewController 
def viewDidLoad 
    @name_label = setup_label [[10, 10], [300, 50]], UIColor.orangeColor, Name 
    @place_label = setup_label [[10, 80], [300, 50]], UIColor.yellowColor, Place 
    @temp_label = setup_label [[10, 150], [300, 50]], UIColor.greenColor, Temperature 
end 

def setup_label frame, bgcolor, text 
    label = UILabel.alloc.initWithFrame(frame) 
    label.textColor = UIColor.darkGrayColor 
    label.backgroundColor = bgcolor 
    label.textAlignment = UITextAlignmentCenter 
    label.text = text.to_s 

    view.addSubview label 
    label 
end 
end 

어떤 아이디어가? 덕분에 사전에 setup_label 방법에서

답변

1

, 당신은 가정 당신의 text 인수가 문자열 객체가 될 수있는 다음 인수, frame, bgcolortext을 허용하고 있습니다.

따라서, 귀하의 viewDidLoad 방법은 다음

def viewDidLoad 
    @name_label = setup_label [[10, 10], [300, 50]], UIColor.orangeColor, "Name" 
    @place_label = setup_label [[10, 80], [300, 50]], UIColor.yellowColor, "Place" 
    @temp_label = setup_label [[10, 150], [300, 50]], UIColor.greenColor, "Temperature" 
end 
해야한다