Advanced Segue 2019年のSegue事情

0d04162c7a3c2907c059a06dbcd23cf4?s=47 tokorom
September 05, 2019

Advanced Segue 2019年のSegue事情

iOSDC Japan 2019 day0 2019/09/05 18:40〜 Track B

0d04162c7a3c2907c059a06dbcd23cf4?s=128

tokorom

September 05, 2019
Tweet

Transcript

  1. 1.

    Advanced Segue 2019೥ͷSegueࣄ৘ ॴ ༑ଠ / Yuta Tokoro, iOS &

    tvOS App Programmer #iOSDC Japan 2019 day0 2019/09/05 18:40ʙ Track B
  2. 19.

    prepareForSegue override func prepare(for segue: …) { if let acceptable

    = segue.destination as? FooAcceptable { if let foo = sender as? Foo { acceptable.accept(foo: foo) } } }
  3. 21.

    viewDidAppear͕ݺ͹Εͳ͍ύλʔϯ override func prepare(for segue: …) { segue.destination.presentationController?.delegate = self

    } func presentationControllerDidDismiss( _ presentationController: UIPresentationController) { // present͞ΕͨViewController͕ด͡ΒΕͨͷΛݕ஌ }
  4. 26.

    override func prepare(for segue: …) { if let acceptable =

    segue.destination as? FooAcceptable { if let foo = sender as? Foo { acceptable.accept(foo: foo) } } } SegueΛ࢖͏έʔεʢ͜Ε·Ͱʣ
  5. 27.

    override func prepare(for segue: …) { if let acceptable =

    segue.destination as? FooAcceptable { if let foo = sender as? Foo { acceptable.accept(foo: foo) } } } class FooViewController: UIViewController, FooAcceptable { var foo: Foo! func accept(foo: Foo) { self.foo = foo } } SegueΛ࢖͏έʔεʢ͜Ε·Ͱʣ
  6. 31.

    Segue Action class SourceViewController: UIViewController { @IBSegueAction func sample1(_ coder:

    NSCoder) -> UIViewController? { return DestinationViewController(coder: coder, value: 1) } @IBSegueAction func sample2(_ coder: NSCoder) -> UIViewController? { return DestinationViewController(coder: coder, value: 2) } }
  7. 32.

    Segue Action class SourceViewController: UIViewController { @IBSegueAction func sample1(_ coder:

    NSCoder) -> UIViewController? { return DestinationViewController(coder: coder, value: 1) } @IBSegueAction func sample2(_ coder: NSCoder) -> UIViewController? { return DestinationViewController(coder: coder, value: 2) } }
  8. 35.

    Segue Action class FooViewController: UIViewController { let value: Int init?(coder:

    NSCoder, value: Int) { self.value = value super.init(coder: coder) } required init?(coder: NSCoder) { fatalError() } override func viewDidLoad() { // label.textʹvalueΛ୅ೖ } } ☺
  9. 51.

    Storyboardͳ͠Ͱ࢖͑Δʁ class PresentSegue: UIStoryboardSegue { override func perform() { source.present(destination,

    animated: true) } } // SegueΛ࢖͏෦෼ let dest = UIViewController() let segue = PresentSegue( identifier: nil, source: self, destination: dest ) segue.perform()
  10. 54.

    Custom Segue͸ ͳΜͰ΋ΞϦ class XibSegue: UIStoryboardSegue { let nibName: String

    override func perform() { let nib = UINib(nibName: nibName, bundle: nil) let objects = nib.instantiate(withOwner: nil) for case let dest as UIViewController in objects { source.present(dest, animated: true) break } } init(source: UIViewController, nibName: String) { // লུ } }
  11. 58.

    Static TableView͔ΒͷopenURL override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

    { switch indexPath.section { case 2: switch indexPath.row { case 0: openURL(“Helpϖʔδ”) default: break } default: break } }
  12. 59.

    Static TableView͔ΒͷopenURL class OpenURLSegue: UIStoryboardSegue { var url: URL {

    //লུ } override func perform() { // ؆ུԽ͍ͯ͠·͢ UIApplication.shared.open(url) } }
  13. 60.

    Static TableView͔ΒͷopenURL class OpenURLSegue: UIStoryboardSegue { var url: URL {

    //লུ } override func perform() { // ؆ུԽ͍ͯ͠·͢ UIApplication.shared.open(url) } } final class OpenHelpPageSegue: OpenURLSegue { override var url: URL { return Constant.helpPageURL } }
  14. 64.

    ڞ௨ͷNavigationControllerͰϥοϓ @IBSegueAction func createFoo(_ coder: NSCoder) -> UIViewController? { let

    navi = // UINavigationController(coder: coder) ??? let dest = // FooViewController(coder: coder, foo: foo) ??? ????????? }
  15. 65.

    ڞ௨ͷNavigationControllerͰϥοϓ class PresentWithNavigationSegue: UIStoryboardSegue { override func perform() { let

    navi = // Storyboard͔ΒNavigationControllerΛload navi.viewControllers = [destination] source.present(navi, animated: true) } }