Upgrade to Pro — share decks privately, control downloads, hide ads and more …

画面遷移と私(iOS)

0d04162c7a3c2907c059a06dbcd23cf4?s=47 tokorom
July 14, 2015

 画面遷移と私(iOS)

画面遷移のときに値渡したりもらったりするところ、もっと簡単に書きたいよね!のアップデート。

0d04162c7a3c2907c059a06dbcd23cf4?s=128

tokorom

July 14, 2015
Tweet

Transcript

  1. ը໘ભҠͱࢲʢiOSʣ ॴ ༑ଠ @tokorom iOS App Programer potatotips-19

  2. ॴ༑ଠ @tokorom

  3. ͪΐ͏Ͳ1೥લ ୈ6ճ potatotips

  4. iOSͷը໘ભҠͱࢲ ॴ ༑ଠ @tokorom iOS App Programer potatotips-19

  5. ը໘ભҠͷྺ࢙

  6. ը໘ભҠͷྺ࢙ •لݩલɿStoryboardొ৔લ •لݩޙɿStoryboardొ৔Ҏޙ •৽࣌୅ɿcontext࣌୅ʁ

  7. Storyboardొ৔Ҏલͷը໘ભҠ let selectVC = SelectItemVC() selectVC.targetUser = self.user self.presentViewController(selectVC, animated:

    true, completion: nil) ભҠઌʹ஋Λ౉͢
  8. Storyboardొ৔Ҏલͷը໘ભҠ selectVC.delegate = self extension MyViewController: SelectItemVCDelegate { override func

    itemDidSelect(item: Item) { // get an item! } } ભҠઌ͔Β஋Λ΋Β͏
  9. Storyboard࣌୅ͷը໘ભҠ self.performSegueWithIdentifier("SelectItems", sender: nil) override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)

    { switch segue.identifier { case: "SelectItems": if let selectVC = segue.destinationViewController as? SelectItemsViewController { selectVC.user = self.user } ભҠઌʹ஋Λ౉͢
  10. Storyboard࣌୅ͷը໘ભҠ @IBAction func unwind(segue: UIStoryboardSegue) { if let vc =

    segue.sourceViewController as? SelectitemVC { let item = vc.selectedItem } } ભҠઌ͔Β஋Λ΋Β͏
  11. WatchKitͰͷྫ self.presentControllerWithName("SelectItem", context: user) override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context)

    self.user = context as? User } ભҠઌʹ஋Λ౉͢
  12. WatchKitͰͷྫ self.presentControllerWithName("SelectItem", context: user) override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context)

    self.user = context as? User } ભҠઌʹ஋Λ౉͢
  13. WatchKitͷcontextͷྑ͍ͱ͜Ζ •ૄ݁߹ʂ •஋Λ౉͢ͱ͖ʹભҠݩͱભҠઌ͕ґଘؔ܎͕Ͱ ͖ͳ͍ •ಉ͡ΠϯλʔϑΣʔεͰͳΜͰ΋౉ͤΔ •Optional BidingͳͲͰ؆୯/҆શʹड͚औΕΔ

  14. ͳ͓… ̍ϲ݄લͷ΅͘

  15. Swift࣌୅͸ΈΜͳ͜͏ॻ͖͍ͨΑͶ self.performSegueWithIdentifier("ItemSelect", context: user) { (item: Item) in let selectedItem

    = item } ભҠઌʹ஋Λ౉͢ˍ΋Β͏
  16. ͪΐ͏Ͳ1೥લ ୈ6ճ potatotips

  17. ͪΐ͏Ͳ1೥લ ୈ6ճ potatotips

  18. ͦͯ͠ࠓ೔ʂ https://github.com/tokorom/SegueContext

  19. ͜ͷॻ͖ํɺͰ͖·͢ʂ self.performSegueWithIdentifier("ItemSelect", context: user) { (item: Item) in let selectedItem

    = item } ભҠઌʹ஋Λ౉͢ˍ΋Β͏
  20. UIViewController+Contextͷྑ͍ͱ͜ •ૄ݁߹ʂ •SwiftͰܕ҆શͳ஋ͷड͚౉͠ •NavigationControllerͱ͔TabBarControllerΛڬΜ Ͱ΋΁ͬͪΌΒ •ΧελϜSegueͳͲෳࡶͳભҠͰ΋࢖͑Δ •Apple Way͔Β͸ͣΕ͗͢ͳ͍ʁ

  21. More Information Yuta ToKoRo iOS App Programer Twitter @tokorom http://www.tokoro.me/

    https://github.com/tokorom/SegueContext