Latest | 0.1.2 |
---|---|
Homepage | https://github.com/xtzPioneer/MGJRouterKit |
License | MIT |
Platforms | ios 8.0 |
Dependencies | MGJRouter |
Authors |
说明
蘑菇街路由器套件,在该基础之上进行了扩展,使其更加简单快捷,主要解决了参数传递问题.利用“runtime”传递参数,同时可以传递多个参数
代码片段
- MGJRouter+TXCreateObject.h文件简介
#import "MGJRouter.h"
NS_ASSUME_NONNULL_BEGIN
/** 传递参数方法键 */
FOUNDATION_EXPORT NSString *const transferParametersMethodKey;
/**
* 蘑菇街路由器套件,在该基础之上进行了扩展,使其更加简单快捷.
*/
@interface MGJRouter (TXCreateObject)
/**
* 创建对象
*
* @param className 类名称
*
* @return 创建的对象
*/
+ (id)createObjectWithClassName:(NSString *)className;
/**
* 创建对象并传递参数
*
* 注意:使用该方法创建对象,必须在该对象中实现"-(void)routeWithParameters:(NSDictionary*)parameters;"方法,否则参数将传递失败
*
* @param className 类名字
*
* @param parameters 参数
*
* @return 创建的对象
*/
+ (id)createObjectWithClassName:(NSString *)className parameters:(NSDictionary*)parameters;
@end
- NSObject+TXTransfer.h文件简介
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* 利用“runtime”传递参数,同时可以传递多个参数
*/
@interface NSObject (TXTransfer)
/**
* 传递参数
*
* @param method 方法 (例如:"routeWithParameters:")
*
* @param parameterss 参数集合 (例如:"@[parameters]")
*
*/
- (void)transferParametersWithMethod:(NSString*)method parameterss:(NSArray*)parameterss;
@end
使用方法
- 导入头文件MGJRouterKit.h即可使用
/** 自动注册 */
+ (void)load {
// 模块1
[MGJRouter registerURLPattern:@"tx://get/module1" toObjectHandler:^id(NSDictionary *routerParameters) {
UIViewController *module1ViewController=[MGJRouter createObjectWithClassName:@"TXModule1ViewController"];
[email protected]"模块1";
UINavigationController *module1NavigationViewController=[[UINavigationController alloc]initWithRootViewController:module1ViewController];
return module1NavigationViewController;
}];
// 模块2
[MGJRouter registerURLPattern:@"tx://get/module2" toObjectHandler:^id(NSDictionary *routerParameters) {
UIViewController *module2ViewController=[MGJRouter createObjectWithClassName:@"TXModule2ViewController"];
[email protected]"模块2";
UINavigationController *module2NavigationViewController=[[UINavigationController alloc]initWithRootViewController:module2ViewController];
return module2NavigationViewController;
}];
// 模块3
[MGJRouter registerURLPattern:@"tx://get/module3" toObjectHandler:^id(NSDictionary *routerParameters) {
UIViewController *module3ViewController=[MGJRouter createObjectWithClassName:@"TXModule3ViewController"];
[email protected]"模块3";
UINavigationController *module3NavigationViewController=[[UINavigationController alloc]initWithRootViewController:module3ViewController];
return module3NavigationViewController;
}];
// 模块4
[MGJRouter registerURLPattern:@"tx://get/module4" toObjectHandler:^id(NSDictionary *routerParameters) {
UIViewController *module4ViewController=[MGJRouter createObjectWithClassName:@"TXModule4ViewController"];
[email protected]"模块4";
UINavigationController *module4NavigationViewController=[[UINavigationController alloc]initWithRootViewController:module4ViewController];
return module4NavigationViewController;
}];
// 测试1
[MGJRouter registerURLPattern:@"tx://push/test1ViewController" toHandler:^(NSDictionary *routerParameters) {
UIViewController *viewController=[MGJRouter createObjectWithClassName:@"TXTest1ViewController" parameters:routerParameters];
[[self currentViewController].navigationController pushViewController:viewController animated:YES];
}];
// 测试2
[MGJRouter registerURLPattern:@"tx://push/test2ViewController" toHandler:^(NSDictionary *routerParameters) {
UIViewController *viewController=[MGJRouter createObjectWithClassName:@"TXTest2ViewController" parameters:routerParameters];
[[self currentViewController].navigationController pushViewController:viewController animated:YES];
}];
// Web模块1
[MGJRouter registerURLPattern:@"tx://get/webModule" toObjectHandler:^id(NSDictionary *routerParameters) {
UIViewController *viewController=[MGJRouter createObjectWithClassName:@"TXWebViewController" parameters:routerParameters];
return viewController;
}];
// Web模块2
[MGJRouter registerURLPattern:@"tx://push/web" toHandler:^(NSDictionary *routerParameters) {
UIViewController *viewController=[MGJRouter createObjectWithClassName:@"TXWebViewController" parameters:routerParameters];
[[self currentViewController].navigationController pushViewController:viewController animated:YES];
}];
}
/** 按钮事件 */
- (void)button2Event:(id)sender{
NSMutableDictionary *parameters=[NSMutableDictionary dictionary];
parameters[@"url"][email protected]"https://github.com/xtzPioneer/MGJRouterKit.git";
[MGJRouter openURL:@"tx://push/web"
withUserInfo:parameters
completion:nil];
}
Installation
MGJRouterKit is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'MGJRouterKit'
Author
xtzPioneer, [email protected]
License
MGJRouterKit is available under the MIT license. See the LICENSE file for more info.
Latest podspec
{ "name": "MGJRouterKit", "version": "0.1.2", "summary": "u8611u83c7u8857u8defu7531u5668u5957u4ef6,u5728u8be5u57fau7840u4e4bu4e0au8fdbu884cu4e86u6269u5c55,u4f7fu5176u66f4u52a0u7b80u5355u5febu6377,u4e3bu8981u89e3u51b3u4e86u53c2u6570u4f20u9012u95eeu9898.", "description": "u8611u83c7u8857u8defu7531u5668u5957u4ef6,u5728u8be5u57fau7840u4e4bu4e0au8fdbu884cu4e86u6269u5c55,u4f7fu5176u66f4u52a0u7b80u5355u5febu6377,u4e3bu8981u89e3u51b3u4e86u53c2u6570u4f20u9012u95eeu9898.u5229u7528u201cruntimeu201du4f20u9012u53c2u6570,u540cu65f6u53efu4ee5u4f20u9012u591au4e2au53c2u6570", "homepage": "https://github.com/xtzPioneer/MGJRouterKit", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "xtzPioneer": "[email protected]" }, "source": { "git": "https://github.com/xtzPioneer/MGJRouterKit.git", "tag": "0.1.2" }, "platforms": { "ios": "8.0" }, "source_files": "MGJRouterKit/Classes/**/*.{h,m}", "dependencies": { "MGJRouter": [] }, "prefix_header_contents": "#import "MGJRouterKit.h"" }
Sun, 24 Mar 2019 11:26:13 +0000