LoginSignup
1
1

More than 5 years have passed since last update.

SwiftでQuickDialogをpushViewControllerで使う

Last updated at Posted at 2015-05-24

QuickDialgはDailogと名付けられているのでモーダルでしか使えないのか?
UINavigationControllerでpushViewControllerしたい。

また、この時、なんとかQuickDialgViewControllerをサブクラス化して、その中でQRootElementを作れないかも試行錯誤してみたが、こっちはちょっと無理っぽい。

単純にQuickDialgのサンプルを参考に以下のようにした。
1.QRootElementはクラス・メソッドで別途作る。
2.上記をrootとして渡してQuickDialogControllerのインスタンスを作り、これをpushViewControllerする。

1.QRootElementはクラス・メソッドで別途作る

QuickDialgのサンプルにならって何たらBuilderのcreateメソッドという名前にする。
Swiftではクラス・メソッドは class func create() と書けばよいらしい。

ExampleQRootBuilder.swift
class ExampleQRootBuilder: NSObject {
    class func create() -> QRootElement {
        let root = QRootElement()
        root.title = "Hello"
        root.grouped = true
        let section = QSection(title: "Example")
        let label = QLabelElement(title: "Hello", value: "Hello!")
        root.addSection(section)
        section.addElement(label)
        return root
    }
}

2.QuickDialogControllerとpushViewController

let root = ExampleQRootBuilder.create()
let qdc = QuickDialogController(root: root)
self.navigationController.pushViewController(qdc, animated: true)

QuickDialogControllerはサブクラスにして戻るボタンなどカスタマイズしてもよい。

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