Recent studies of the components, read a lot of information, meet a lot of pits, where it recorded a small partner to facilitate reference. Great God and not as I will be expressed in the most plain simple language, we hope to know more friends, I wish for world peace
Component-based component-based personal feeling high maintenance costs, mainly for decoupling, but good foundation
First, a project under the same components of the realization of ideas, mainly used middleware CTMediator (interpreted it as a bridge of communication, such as jumping between many controllers direct push, then use the middleware CTMediator is through CTMediator push of)
Jump to realize two controllers:
1. CTMediator project import file, of course, be introduced into pod pod 'CTMediator'
2. Write the jump destination file: the purpose is to jump to the target controller to write a preparation method provides a way for the third step CTMediator + CTMediatorManager class parameters
Note: Target_TotalTargetVC Target_ object name prefix is fixed,
Action_nativeDetailMainViewController Action_ method name prefix is fixed, with reference to the code visible reason CTMediator
Target_TotalTargetVC.h Code
#import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface Target_TotalTargetVC : NSObject - (UIViewController *)Action_nativeDetailMainViewController:(NSDictionary *)params; @end NS_ASSUME_NONNULL_END
Target_TotalTargetVC.m
#import "Target_TotalTargetVC.h" #import "MainViewController.h" @implementation Target_TotalTargetVC - (UIViewController *)Action_nativeDetailMainViewController:(NSDictionary *)params { MainViewController *VC = [[MainViewController alloc]init]; VC.dic = params; return VC; } @end
3. Write CTMediator classification CTMediator + CTMediatorManager
This classification purposes: the middleware CTMediator by a method of call, the parameters are derived from the method Target_TotalTargetVC object, the result returned jump controller UIViewController
CTMediator+CTMediatorManager.h
#import "CTMediator.h" NS_ASSUME_NONNULL_BEGIN @interface CTMediator (CTMediatorManager) - (UIViewController *)CTMediator_viewMainViewController:(NSDictionary*)params; @end NS_ASSUME_NONNULL_END
CTMediator+CTMediatorManager.m
#import "CTMediator+CTMediatorManager.h" // 这里指的是Target_TotalTargetVC.h对象 NSString * const kCTMediatorTotalTargetObject = @"TotalTargetVC"; // 这指的是Target_TotalTargetVC.m中 Action_nativeDetailMainViewControllerf 方法 NSString * const kCTMediatorActionNativeDetailMainViewController = @"nativeDetailMainViewController"; @implementation CTMediator (CTMediatorManager) - (UIViewController *)CTMediator_viewMainViewController:(NSDictionary*)params { //Since CTMediator_viewMainViewController is extended CTMediator, it may be used as a method CTMediator of the UIViewController * the viewController = [Self performTarget: kCTMediatorTotalTargetObject Action: kCTMediatorActionNativeDetailMainViewController the params : the params ]; IF ([the viewController The isKindOfClass: [the UIViewController class ]]) { return the viewController; } the else { // here exception handling scenarios, depending on how to handle specific product return [[the UIViewController the alloc] the init]; } } @end
4. The final step, where you need to jump written on it
#pragma mark - 跳转 - (void)toMainViewController:(BOOL)isAnimate{ UIViewController *VC = [[CTMediator sharedInstance]CTMediator_viewMainViewController:@{@"key":@"CTMetor传值你好"}]; [self.navigationController pushViewController:VC animated:isAnimate]; }
Here only write the same project middleware, next to an article to jump between different project.