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

古き良きsendAction (in potatotips #26)

0d04162c7a3c2907c059a06dbcd23cf4?s=47 tokorom
February 17, 2016

古き良きsendAction (in potatotips #26)

UIApplicationのsendActionを見直そう

0d04162c7a3c2907c059a06dbcd23cf4?s=128

tokorom

February 17, 2016
Tweet

Transcript

  1. ݹ͖ྑ͖ sendAction ॴ ༑ଠ @tokorom iOS App Programer potatotips-26

  2. ॴ༑ଠ @tokorom (ϑϦʔλʔʣ potatotipsӡӦ૭ޱ / potatotipsΛओ࠵͍͚ͨͩΔձࣾ͞Μืूதʂ

  3. UIApplication - sendAction

  4. UIApplication - sendAction •࣮ࡍʹ࢖͍ͬͯΔਓ͸Ͳͷ͘Β͍ʁ •ͦ΋ͦ΋ଘࡏΛ஌͍ͬͯΔʁ •ʢUIControlͷ΄͏͸ͨ·ʹݟΔ͚Ͳ…ʣ •ʢ࢖͍ͬͯΔͷΛ͋Μ·Γݟͨ͜ͱͳ͍ʣ

  5. UIApplication - sendAction NEW! iOS 9 Ͱ ྲྀ੕ ͷ͝ͱ͘ݱΕͨ ࠷ڧ

    ͷ function !?
  6. UIApplication - sendAction iPhone OS 2 ͔Β ͘͝ ී௨ ʹଘࡏ͢Δ

    ͋·Γ ࢖ΘΕͳ͍ ΍ͭ
  7. // hoge: ΛൃՐ let app = UIApplication.sharedApplication() app.sendAction("hoge:", to: xxx,

    from: sender, forEvent: nil) // hoge: func hoge(sender: AnyObject) { print("hoge!!") } αϯϓϧίʔυ UIApplication - sendAction
  8. UIApplication - sendAction •ग़ͨΑɺจࣈྻࢦఆʂ •Objective-C෩selectorࢦఆ͕ݹष͍ •࢖͍ॴ͋Δͷʁ •RxSwiftͱ͔࢖͏΄͏͕Α͘ͳ͍ʁ app.sendAction("hoge:", to: xxx,

    from: sender, forEvent: nil) ͓͓ΉͶ ਖ਼ղ
  9. Responder Chain (in UIKit)

  10. Responder Chain (in UIKit) •Ԟ·ͬͨ֊૚ͰൃՐ •֊૚ͷͲ͜Ͱ΋ड͚ΒΕΔ •DelegateͷΑ͏ʹreceiverΛड͚ ౉͢ඞཁ͕ͳ͍ •ଞखஈͰಉ͡ߏ଄Λ࣮ݱ͢Δͷ͸ ೉͍͠

  11. Responder Chain (in UIKit) app.sendAction("hoge:", to: xxx, from: sender, forEvent:

    nil) app.sendAction("hoge:", to: , from: sender, forEvent: nil) app.sendAction("hoge:", to: nil, from: sender, forEvent: nil)
  12. Responder Chain (in UIKit) UITabBarController UIViewController UITabBarController UIViewController UIViewController UIViewController

  13. Responder Chain (in UIKit) UITabBarController UIViewController UITabBarController UIViewController UIViewController UIViewController

    UITableView UITableViewCell UIView UIButton
  14. sendActionͷྑ͍ͱ͜Ζ •Responder Chainͳૄ݁߹ͳ࢓૊ΈͰը໘ߏ੒ ͕มΘͬͯ΋ར༻Ͱ͖Δ •CocoaͷࠜװͱͳΔ࢓૊ΈͷͨΊྲྀߦʹࠨӈ͞ Εͳ͍

  15. sendActionͷμϝͳͱ͜Ζ •ΠϯλʔϑΣʔε͕ݹ͍ •จࣈྻࢦఆ •selector?? •Ҿ਺ʹಛఆͷObjectΛ౉ͮ͠Β͍

  16. ৽͍͠ΠϯλʔϑΣʔεͰϥοϐϯά // hoge: ΛൃՐ HogeEvent(hoge: hoge).fireFrom(self.view) // hoge: func hoge(sender:

    AnyObject) { guard let hoge: Hoge =ɹContext.valueFor(sender) else { return } print("hoge: \(hoge)") }
  17. ·ͱΊ •UIApplicationͷsendAction͸৔߹ʹΑͬͯ͸༗ ༻ •ݹ͖ྑ͖ػೳ͕ͩը໘ߏ੒͕ෳࡶͳݱ୅Ͱͦ͜ ར༻Ձ஋͕͋Δ •ੲ͔Β͋Δػೳʹ΋ҙ֎ͱ࢖͑Δ΋ͷ͕຾ͬͯ ͍Δ͔΋ʁ

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