LoginSignup
0

More than 5 years have passed since last update.

xibファイルを使う。

Posted at

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

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0