LoginSignup
2
2

More than 5 years have passed since last update.

RubyMotionでStoryboardを使う

Posted at

プロジェクトを作成

$ motion create storyboard_test
$ cd storyboard_test

Storyboardファイル作成

XcodeでWorkspaceを作成します。

スクリーンショット 2016-01-14 15.35.28.png

左のファイルとグループの領域で右クリックをしAdd Files to ... を選択します。

スクリーンショット 2016-01-14 15.39.13.png

RubyMotionプロジェクトのフォルダーを選択しますが、この時OptionsでCreate groups for any added foldersを選択します。

スクリーンショット 2016-01-14 15.41.47.png

フォルダーが黄色で表示されていればOKです。

resourcesフォルダー上で右クリックしNew File...を選択します。

スクリーンショット 2016-01-14 15.48.14.png

Storyboardを選択して作成します。

スクリーンショット 2016-01-14 15.49.59.png

UIViewControllerを追加し、Is Initial View Controllerにチェックを入れます。

スクリーンショット 2016-01-14 15.51.24.png

Rakefileの編集

RakefileにStoryboardを使うことを指定します。

app.info_plist['UIMainStoryboardFile'] = 'Storyboard'の行です。

Motion::Project::App.setup do |app|
  # Use `rake config' to see complete project settings.
  app.name = 'storyboard_test'

  # ここを追加
  app.info_plist['UIMainStoryboardFile'] = 'Storyboard'

end

app_delegate.rbの編集

windowメンバ変数を追加し、-application:didFinishLaunchingWithOptions:ではもともとあったコードを削除しtrueを返すだけにします。

app_delegate.rb
class AppDelegate

  # ここを追加
  attr_accessor :window

  def application(application, didFinishLaunchingWithOptions:launchOptions)
    true
  end
end

確認

$ rake

スクリーンショット 2016-01-14 16.00.40.png

後書き

前に試した時にダメだったのでずっと-application:didFinishLaunchingWithOptions:内でStoryboardを読み込むコードを書いて使ってたんですが、久しぶりに試したら下のメッセージが出てwindows propertyがないためだと分かった次第です。

The app delegate must implement the window property if it wants to use a main storyboard file.
2
2
0

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
2
2