storyboard変数はUIViewControllerに定義されている変数です。
@available(iOS 5.0, *)
public var storyboard: UIStoryboard? { get }
swift
1// storyboard?は現在このViewConrollerが配置されているStoryboardを指します
2// ※storyboardに配置されているとは限らなく、取得できない場合があるのでOptional Chainingの『?』になっています
3
4// instantiateViewControllerWithIdentifierは以下のように定義されていて
5public func instantiateViewControllerWithIdentifier(identifier: String) -> UIViewController
6
7// storyboardのViewControllerに付けられたStoryboard IDを指定してそのUIViewConrollerを返します。
8// そのViewConrollerが取得出来た時にifの中に入りそのViewControllerに対してデータを設定しています。
9
10if let nextQuestionViewController = storyboard?.instantiateViewControllerWithIdentifier("question") as? QuestionViewController {
11 nextQuestionViewController.questionDate = nextQuestion
12 self.presentViewController(nextQuestionViewController, animated: true, completion: nil)
13}
Storyboard名を指定してStoryboardを取得する場合は以下になります。
var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
★ Optional Chainingについては以下を一読ください。
[Swift] Optional 型についてのまとめ Ver2 - Optional Chaining
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/20 04:59