Guest User

Untitled

a guest
Jan 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #import "UIResponder+Router.h"
  2.  
  3. @implementation UIResponder (Router)
  4.  
  5. - (void)routerEventWithName:(NSString *)eventName userInfo:(NSDictionary *)userInfo
  6. {
  7. [[self nextResponder] routerEventWithName:eventName userInfo:userInfo];
  8. }
  9.  
  10. @end
  11.  
  12. [self routerEventWithName:kBLGoodsDetailBottomBarEventTappedBuyButton userInfo:nil];
  13.  
  14. #pragma mark - event response
  15. - (void)routerEventWithName:(NSString *)eventName userInfo:(NSDictionary *)userInfo
  16. {
  17.  
  18. /*
  19. do things you want
  20. */
  21. // call the upper ,by ResponderChain
  22. // [super routerEventWithName:eventName userInfo:userInfo];
  23. }
  24.  
  25. #pragma mark - event response
  26. - (void)routerEventWithName:(NSString *)eventName userInfo:(NSDictionary *)userInfo
  27. {
  28.  
  29. NSInvocation *invocation = self.eventStrategy[eventName];
  30. [invocation setArgument:&userInfo atIndex:2];
  31. [invocation invoke];
  32.  
  33. // call the upper ,by ResponderChain
  34. // [super routerEventWithName:eventName userInfo:userInfo];
  35. }
  36.  
  37. - (NSDictionary <NSString *, NSInvocation *> *)eventStrategy
  38. {
  39. if (_eventStrategy == nil) {
  40. _eventStrategy = @{
  41. kBLGoodsDetailTicketEvent:[self createInvocationWithSelector:@selector(ticketEvent:)],
  42. kBLGoodsDetailPromotionEvent:[self createInvocationWithSelector:@selector(promotionEvent:)],
  43. kBLGoodsDetailScoreEvent:[self createInvocationWithSelector:@selector(scoreEvent:)],
  44. kBLGoodsDetailTargetAddressEvent:[self createInvocationWithSelector:@selector(targetAddressEvent:)],
  45. kBLGoodsDetailServiceEvent:[self createInvocationWithSelector:@selector(serviceEvent:)],
  46. kBLGoodsDetailSKUSelectionEvent:[self createInvocationWithSelector:@selector(skuSelectionEvent:)],
  47. };
  48. }
  49. return _eventStrategy;
  50. }
Add Comment
Please, Sign In to add comment