プロジェクトを作成
$ motion create storyboard_test
$ cd storyboard_test
Storyboardファイル作成
XcodeでWorkspaceを作成します。
左のファイルとグループの領域で右クリックをしAdd Files to ... を選択します。
RubyMotionプロジェクトのフォルダーを選択しますが、この時OptionsでCreate groups for any added foldersを選択します。
フォルダーが黄色で表示されていればOKです。
resourcesフォルダー上で右クリックしNew File...を選択します。
Storyboardを選択して作成します。
UIViewControllerを追加し、Is Initial View Controllerにチェックを入れます。
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を返すだけにします。
class AppDelegate
# ここを追加
attr_accessor :window
def application(application, didFinishLaunchingWithOptions:launchOptions)
true
end
end
確認
$ rake
後書き
前に試した時にダメだったのでずっと-application:didFinishLaunchingWithOptions:内でStoryboardを読み込むコードを書いて使ってたんですが、久しぶりに試したら下のメッセージが出てwindows propertyがないためだと分かった次第です。
The app delegate must implement the window property if it wants to use a main storyboard file.