#author("2016-05-24T16:27:52+09:00","default:wikiwriter","wikiwriter") &tag(Storyboard); *目次 [#ff073cc6] #contents *関連ページ [#h2ee4744] -[[Xcode]] -[[UIKit]] -[[./セグエ]] -[[./分割して使う]] -[[./StoryboardReference]] *参考情報 [#t1aa4d0a] -[[[iOS]これからiOSアプリを作る方向け Storyboardで画面遷移を作る | Developers.IO:http://dev.classmethod.jp/smartphone/iphone/remind-storyboard/]] *概要 [#y23e5151] -画面遷移の仕組み *全般 [#pa5e7896] **ストーリーボードのデバイスがデカイ? [#ke7d76f9] -一応仕様らしい。ただしIBでView Controllerを選択しSimulated MetricsをInferredからiPhone 4.7インチとかに変更する。 -iPhoneに固定することもできるらしい。[[SwiftをiOSシミュレータで実行:「はじめてのSwiftプログラミング」著者サポートページ:http://supportdoc.net/support-swift/xcode6.html]] **Storyboardを使わない方法に関して [#s9a8a6c2] -[[StoryBoardを使わない方法 - Qiita:http://qiita.com/shou1471/items/637f7500698c3c5b0bc0]]…状態の復元がStoryboardなしだとできないという情報あり。 -[[Q. StoryboardとXIBはどう使い分ければいいんだろうか? - Qiita:http://qiita.com/gfx/items/dfd850749a1493e68513]]…Storyboardとxibの使い分け -以上を踏まえ、Appleが標準としてStoryboardを押していることから、Storyboardをメインに使いつつ複雑になってきたら複数に分割する手法がいいのかもしれない。 *ビューコントローラー [#r8173a1e] **初期ビューコントローラーを指定する [#c2fcdf50] -左側に矢印のついたビューコントローラーがないと何も表示されない。 -Attributes Inspectorを開き、View Controllerの「Is Initial View Controller」をチェックする。 **プログラムコードからストーリーボードのビューコントローラーを呼び出す [#ac129a42] -以下のように呼び出す #pre{{ let storyboard = UIStoryboard(name: "Main", bundle: nil) let vc:UIViewController = storyboard.instantiateViewControllerWithIdentifier("WebViewController") let webViewController = vc as! WebViewController webViewController.initialUrl = urlString self.navigationController!.presentViewController(vc, animated: true, completion: nil) }} -呼び出し先のビューコントローラーには、Storyboard IDを割り当てておく。Identity InspectorのStoryboard IDで設定できる。 *テーブルビュー [#jc45a166] **一番上のセルがステータスバーにかぶってしまう [#i755c643] -最初にテーブルのサイズをステータスバー以下にしておいてAutoLayoutのPinを設定すれば良い。 -限界まで設定するとかぶるが、ステータスバーの下にしてから始めれば自動的に隙間があく。 **左右のマージン [#a8d5b827] -Pinの設定でConstraint to Marginのせい。 **UITableViewControllerを使う [#fba5a154] -Single View Applicationで作成。 -ViewController.swiftを削除。 -Main.storyboardの中のView Controllerを削除。かわりにTable View Controllerを追加。 --Attributes InspectorのView Controllerセクションにある「Is Initial View Controller」にチェック。 -「File > New」からUITableViewControllerクラスのサブクラス(例MyTableViewController)を作成して追加。 -Table View ControllerのクラスをMyTableViewControllerとする。 -UITableViewControllerにナビゲーションコントローラーやツールバーを追加したい場合、下記のナビゲーションコントローラーを参照のこと。 ※UITableViewControllerを使わないと、Static Cellsが使えない。 *ナビゲーションコントローラー [#rdd06163] **ナビゲーションコントローラーを使う [#d9f032de] -[[Xcode6.xのStoryboardにてToolBar(下のバー)が出ない人へ | 3URPRISE.BLOG:http://smileapps.sakura.ne.jp/blg/?p=902]] -既存のView Controllerを選択し、「Editor > Embed in > Navigation Controller」を実行。 ※ちなみに[[ios - StoryboardのNavigation Barの存在理由 - スタック・オーバーフロー:http://ja.stackoverflow.com/questions/12606/storyboard%E3%81%AEnavigation-bar%E3%81%AE%E5%AD%98%E5%9C%A8%E7%90%86%E7%94%B1]]によると、NavigationBarを個別に追加する必要はほとんどないらしい。 **ナビゲーションコントローラーに編集ボタンを追加 [#r031d9fc] -上の方法でナビゲーションコントローラーを追加した場合、ViewControllerのviewDidLoadで以下を実行する。 #pre{{ override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.navigationItem.rightBarButtonItem = self.editButtonItem() } }} **ナビゲーションコントローラーにツールバーを表示する [#p751da52] -ナビゲーションコントローラーを使っている場合、Attributes Inspectorの「Shows Toolbar」にチェックを入れる。 -Interface Builderで操作してもだめ。 **ナビゲーションコントローラーのツールバーの表示非表示を切り替える [#u998019c] -例えば編集ボタンが押されたとき、ツールバーを非表示にしたいような場合 #pre{{ override func setEditing(editing: Bool, animated: Bool) { super.setEditing(editing, animated: animated); self.navigationController?.setToolbarHidden(editing, animated:true) } }} *Tips [#veab801d] **独自のUIViewControllerを使用する [#yc7b2ade] -Storyboardで「ビューコントローラー」の部品を追加。 -独自のUIViewControllerのサブクラスを追加。 -Identity Inspectorでビューコントローラーの部品のクラスを独自クラスに変更する。 **ナビゲーションコントローラーの2番目のビューコントローラーにタイトルを設定する [#oa1d8186] -[[ios - Cannot add Bar Button to Second Page through Interface Builder - Stack Overflow:http://stackoverflow.com/questions/27822120/cannot-add-bar-button-to-second-page-through-interface-builder]]にあるように、2番目のビューコントローラーにNavigation itemを追加しそれにタイトルを設定する。 -もしくはコードで設定する。 **ステータスバーまわりのはなし [#v9f01d4b] -[[やはりお前らのiOS7対応は間違っている(解説編) - Qiita:http://qiita.com/yimajo/items/254c7cebab7864678246]] *トラブルシューティング [#o7276908] **Scene is unreachable due to lack of entry points [#y9471d46] -[[ios - Scene is unreachable due to lack of entry points - Stack Overflow:http://stackoverflow.com/questions/31460469/scene-is-unreachable-due-to-lack-of-entry-points]]によるとStoryboardにIDを割り当てればいいらしい。