有谁知道为什么以下 RubyMotion 代码中的按钮在单击时不会触发 say_something 方法...
class HomeViewController < UIViewController
def loadView
self.view = UIImageView.alloc.init
end
def viewDidLoad
view.image = UIImage.imageNamed('background.png')
@action_button = UIButton.buttonWithType UIButtonTypeCustom
@action_button.frame = [[100, 100], [224, 229]]
@action_button.setBackgroundImage(UIImage.imageNamed("home_button_green.png"), forState: UIControlStateNormal)
@action_button.addTarget(self, action: :say_something, forControlEvents: UIControlEventTouchUpInside)
view.addSubview @action_button
end
def say_something
@alert_box = UIAlertView.alloc.initWithTitle("Hello World",
message:"Hi",
delegate: nil,
cancelButtonTitle: "ok",
otherButtonTitles:nil)
# Show it to the user
@alert_box.show
end
def viewDidAppear(animated)
end
end