标签:animate 映射 delegate and tabbar tor 自己的 sda 独立
简述CTMediator
SEL action = NSSelectorFromString(@"Action_response:"); NSObject *target = [[NSClassFromString(@"Target_NoTargetAction") alloc] init];
[target performSelector:action withObject:params];
NSMethodSignature* methodSig = [target methodSignatureForSelector:action]; if(methodSig == nil) { return nil; } const char* retType = [methodSig methodReturnType]; if (strcmp(retType, @encode(void)) == 0) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSig]; [invocation setArgument:¶ms atIndex:2]; [invocation setSelector:action]; [invocation setTarget:target]; [invocation invoke]; return nil; }
@interface Target_Mine : NSObject - (id)Action_nativeFetchSportsResultVC:(NSDictionary *)param; - (void)Action_remoteAlertSportsResultVC:(NSDictionary *)param; @end
@implementation Target_Mine - (id)Action_nativeFetchSportsResultVC:(NSDictionary *)param { UIViewController *vc = [[FZMineCoordinator sharedFZMineCoordinator] targetVCWithClassName:NSStringFromClass([FZSportsResultVC class])]; if ([vc isKindOfClass:[FZSportsResultVC class]]) { [(FZSportsResultVC *)vc configContent:param[@"title"]]; } return vc; } - (void)Action_remoteAlertSportsResultVC:(NSDictionary *)param { UIViewController *vc = [[FZMineCoordinator sharedFZMineCoordinator] targetVCWithClassName:NSStringFromClass([FZSportsResultVC class])]; if ([vc isKindOfClass:[FZSportsResultVC class]]) { [(FZSportsPlanVC *)vc configContent:param[@"title"]]; } id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate; UITabBarController *rootVC = [[appDelegate window] rootViewController]; [rootVC.childViewControllers[0] pushViewController:vc animated:YES]; } @end
Part3: CTMediator+ModuleA组件通讯实际使用类
- (IBAction)goSportsPlanDetail:(UIButton *)sender { UIViewController *vc = [[CTMediator sharedInstance] Mediator_fetchSportsPlanVC:@{@"title":[sender currentTitle]}]; [self.navigationController pushViewController:vc animated:YES]; }
- (NSMutableDictionary *)routes { if (!_routes) { _routes = [[NSMutableDictionary alloc] init]; } return _routes; }
但是URL对应像UIImage,NSData这样的非常规对象是很难传递的。
[ModuleManager registerClass:ClassA forProtocol:ProtocolA]
使用映射表
[ModuleManager classForProtocol:ProtocolA]
+ (void)load { [MGJRouter registerURLPattern:@"engineer://SportsPlanVC" toObjectHandler:^id(NSDictionary *routerParameters) { FZSportsPlanVC *planVC = [FZSportsPlanVC new]; [planVC configContent:routerParameters[@"MGJRouterParameterUserInfo"][@"title"]]; return planVC; }]; }
+ (void)load { [[FZProtocolMediator sharedFZProtocolMediator] registerProtocol:NSProtocolFromString(@"FZModuleMineProtocol") forClass:[FZModuleMineProtocolImplete class]]; }
- (IBAction)mgj_goSportsPlanDetail:(UIButton *)sender { UIViewController *vc = [MGJRouter objectForURL:@"engineer://SportsPlanVC" withUserInfo:@{@"title":[sender currentTitle]}]; [self.navigationController pushViewController:vc animated:YES]; }
- (IBAction)protocol_class_goSportsPlanDetail:(UIButton *)sender { Class<FZModuleMineProtocol> class = [[FZProtocolMediator sharedFZProtocolMediator] classForProtocol:NSProtocolFromString(@"FZModuleMineProtocol")]; UIViewController *vc = [class fetchSportsPlanVC:sender.currentTitle]; [self.navigationController pushViewController:vc animated:YES]; }
简述组件化解决方案CTMediator与MGJRouter的主要思想
标签:animate 映射 delegate and tabbar tor 自己的 sda 独立
原文地址:https://www.cnblogs.com/zhou--fei/p/10306657.html