YJRouter
常规打开方式
UIViewController *vc = [[UIViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
或者
UIViewController *vc = [[UIViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:nav animated:YES completion:nil];
如何使用 YJRouter
- CocoaPods 安装:
pod 'YJRouter'
AppDelegate.m
[YJRouter sharedInstance].navigationClassName = @"UINavigationController"; // 或者你自己的UINavigationController的子类
[YJRouter sharedInstance].appPrefixName = @"app"; // 默认为‘app’
[YJRouter registerURLPattern:@"app://first" forClass:@"FirstViewController"]; // 将FirstViewController注册为first,对应URL则为app://first
[YJRouter registerURLPattern:@"app://second/:id/:name" forClass:@"SecondViewController"]; // 将SecondViewController注册为second,对应URL则为app://
[YJRouter registerURLPatternWithArray:array]; // 可以由一个配置文件生成一个数组,数组中的元素为字典,key为controller和url_pattern
需要打开新页面的地方
[YJRouter openURL:@"app://first"]; // 将以push的方式打开FirstViewController
[YJRouter openURL:@"app://first?showtype=present" withObject:@[@"1", @"2"]]; // 将以modal的方式打开FirstViewController, 并传递一个数组对象
[YJRouter openURL:@"app://second/12/yjrouter?desc=description"]; // 打开SecondViewController,同时传递id,name,desc三个参数
获取传递过来的参数
- (void)viewDidLoad {
[super viewDidLoad];
NSDictionary *dic = [YJRouter extractParam:@"first"];
if (dic != nil) {
NSString *ID = [dic objectForKey:@"id"];
NSString *name = [dic objectForKey:@"name"];
NSString *desc = [dic objectForKey:@"desc"];
if (dic[YJRouterParameterObject] != nil) {
NSArray *array = dic[YJRouterParameterObject];
}
}
}