此方案使用Casa在github上提供的CTMediator库。
大概流程如下图
模块调用示意图每个模块都提供一个Action接口和一个Mediator的category,
其他模块调用category中的方法,category通过runtime调用Action中的方法。
项目调用实例:
[[MTMediator sharedInstance] position_pushOrderEditViewController:order];
#import "MTMediator+Position.h"
NSString * const kMTMediatorTargetPosition = @"Position";
NSString * const kMTMediatorActionPushOrderEditViewController = @"pushOrderEditViewController";
NSString * const kMTMediatorActionOpenPositions = @"openPositions";
@implementation MTMediator (Position)
- (UIViewController *) position_pushOrderEditViewController:(MTOrder *)order {
UIViewController *viewController = [self performTarget:kMTMediatorTargetPosition action:kMTMediatorActionPushOrderEditViewController params:@{@"order":order} shouldCacheTarget:NO];
if ([viewController isKindOfClass:[UIViewController class]]) {return viewController;
}
else{return [[UIViewController alloc] init];
}
}
#import "MTOrderEditController.h"
@implementation Target_Position
- (UIViewController *)Action_pushOrderEditViewController:(NSDictionary *)params {
MTOrderEditController *editVC = [[MTOrderEditController alloc] init];
MTOrder*order = params[@"order"];
editVC.orderModel= order;
editVC.quotationModel = order.qutationWeakModel;
UIViewController *controler = [UIViewController mt_getCurrentViewController];
if (controler.navigationController) [controler.navigationController pushViewController:editVC animated:true];
returneditVC;}
网友评论