Save 37% off PRO during our Black Friday Sale! »

もっと早く教えて欲しかった画面遷移

 もっと早く教えて欲しかった画面遷移

869dbbb5dbfd450495c83b5f92285498?s=128

PKPK-Carnage

January 22, 2019
Tweet

Transcript

  1. ΋ͬͱૣ͘ڭ͑ͯཉ͔ͬͨ͠ը໘ભҠ 1/22 ͋Δ͋ΔLTʙεϚϗΞϓϦ։ൃΤϯδχΞʙ Vol.2 PKPK-Carnage 1

  2. About me • iOSྺ2೥ͪΐͬͱ • Qiita → @PKPK-Carnage • Github

    → PKPK-Carnage • Twitter → @PKPK-Carnage
  3. ը໘ભҠͬͯͲ͏΍ͬͯ·͔͢ʁ 3

  4. ηάΤ vs ίʔυ 4

  5. ηάΤ 5

  6. Hoge͔ΒFugaʹભҠͯ͠ɺ Fuga͔ΒPiyoʹભҠͯ͠ɾɾɾ 6

  7. 7

  8. 8

  9. 9 extension HogeViewController { @IBAction private func didTapFugaButton(_ sender: UIButton)

    { self.performSegue(withIdentifier: "showFuga", sender: sender.tag) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let vc = segue.destination as? FugaViewController { if let value = sender as? Int { vc.value = value } } } }
  10. ͋ͷը໘͔Β͸௚઀ͦͷը໘ʹભҠͯ͠ɺ ͦͷը໘͔Β͸3छྨͷը໘ʹભҠͯ͠ɾɾɾ 10

  11. 11

  12. 12

  13. 13 extension HogeViewController { @IBAction private func didTapFugaButton(_ sender: UIButton)

    { self.performSegue(withIdentifier: "showFuga", sender: sender.tag) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let vc = segue.destination as? FugaViewController { if let value = sender as? Int { vc.value = value } } } }
  14. 14 extension HogeViewController { @IBAction private func didTapFugaButton(_ sender: UIButton)

    { self.performSegue(withIdentifier: "showFuga", sender: sender.tag) } @IBAction private func didTapPiyoButton(_ sender: UIButton) { self.performSegue(withIdentifier: "showPiyo", sender: sender.currentTitle) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let vc = segue.destination as? FugaViewController { if let value = sender as? Int { vc.value = value } } else if let vc = segue.destination as? PiyoViewController { if let value = sender as? String { vc.value = value } } } }
  15. ! 15

  16. (PPE #BE • ભҠΛࢹ֮తʹݟΕΔ • ؆୯ʹ࣮૷Ͱ͖Δ 22 • ը໘਺͕૿͑ΔͱΧΦε •

    ίϯϑϦΫτͰઈ๬͢Δ • identifierͰભҠઌΛࢦఆ͠ͳ͚ Ε͹ͳΒͳ͍ • prepareϝιου͕ѻ͍ͮΒ͍
  17. ίʔυ 23

  18. 24 extension HogeViewController { @IBAction private func didTapFugaButton(_ sender: UIButton)

    { self.performSegue(withIdentifier: "showFuga", sender: sender.tag) } }
  19. 25 extension HogeViewController { @IBAction private func didTapFugaButton(_ sender: UIButton)

    { let vc = FugaViewController(nibName: "FugaViewController", bundle: .main) vc.value = sender.tag self.navigationController?.pushViewController(vc, animated: true) } }
  20. (PPE #BE • ஋౉ָ͕͠ʹͰ͖Δ • ίϯϑϦΫτͯ͠΋௚͠΍͍͢ • segueΑΓ҆৺ 32 •

    ભҠΛࢹ֮తʹݟΕͳ͘ͳΔ • Ͳͷը໘ʹભҠ͢Δ͔೺Ѳ͢Δ ͷ͕େม • ॲཧΛॻ͘ͷ͕໘౗
  21. " 34

  22. protocol + extensitonͰղܾ͢Δ 35

  23. ભҠ͢ΔͨΊͷprotocolΛ࡞Δ 36 protocol FugaTransitable: class { func transitToFuga(value: Int) }

    extension FugaTransitable where Self: UIViewController { func transitToFuga(value: Int) { let vc = FugaViewController(nibName: "FugaViewController", bundle: .main) vc.value = value self.navigationController?.pushViewController(vc, animated: true) } }
  24. protocolΛద༻͢Δ 37 extension HogeViewController: FugaTransitable { @IBAction private func didTapFugaButton(_

    sender: UIButton) { self.transitToFuga(value: sender.tag) } }
  25. ભҠͷprotocolΛ௥Ճ͍ͯ͘͠ 38 extension HogeViewController: FugaTransitable, PiyoTransitable { @IBAction private func

    didTapFugaButton(_ sender: UIButton) { self.transitToFuga(value: sender.tag) } }
  26. (PPE #BE • ஋౉ָ͕͠ʹͰ͖Δ • ίϯϑϦΫτͯ͠΋௚͠΍͍͢ • segueΑΓ҆৺ • ࣮૷͞Ε͍ͯΔprotocolͰભҠઌ

    ͕Θ͔Δ • ॲཧΛॻ͘ͷָ͕ 42 #
  27. ·ͱΊ • iOSͰը໘ભҠ͸ηάΤͱίʔυͷ2ύλʔϯ͋Δ • ͦΕͧΕϝϦοτͱσϝϦοτ͕͋Δ • protocolͱextensionΛۦ࢖͢Ε͹ίʔυͰͷσϝϦοτΛഉ আͰ͖Δ • ͜ͷ΍ΓํΛ஌ͬͨ࣌ʹ΋ͬͱૣ͘஌Γ͔ͨͬͨͱࢥͬͨ

    47
  28. ͓ΘΓ 48