1.3からInterfaceBuilderで生成したxibファイルを使えるようになった模様。
xibファイルをresources
フォルダに入れて、ViewController
を生成する際、下記のようにする。
app/app_delegate.rb
# UseXibViewController.xibを読み込む
@window.rootViewController = UseXibViewController.alloc.initWithNibName("UseXibViewController",
bundle: nil)
xibファイル内のボタンなどはtagで参照する。
app/use_xib_view_controller
class UseXibViewController < UIViewController
def viewDidLoad
# xibに設定したタグでボタンを特定
@button = self.view.viewWithTag 1
@button.addTarget(self,
action: "clicked",
forControlEvents: UIControlEventTouchUpInside
)
end
end
def clicked
alert = UIAlertView.new
alert.message = "Hello"
alert.show
end