Routable在项目中使用

Routable

使用优势:

1.减少 UIViewController 之间的耦合

2.调用App

3.不用限制 随意跳转 (在view上也可以跳转,点击推送也可以直接在appdelagate跳转任意Controller)

4.在一个基类里注册方便统一管理,提高代码的复用性规范性

另:不影响以前代码使用

使用方法:

分Appdelegate+Routable (负责调用各模块的Routable), RoutableConstant (传参数时 对应的param的key 都在这里 ), HomeRoutable (针对Home模块创建Routable 该模块下的VC都在里面注册和写跳转方法,类似的还有MineRoutable等)

在HomeRoutable里 要先注册 再写跳转方法

@implementation HomeRoutable

//跳转VC注册
+ (void)loadHomeRoutable {
Routable *routable = [Routable sharedRouter];
[routable map:[FirstViewController Identify] toController:[FirstViewController class]];
[routable map:[SecondViewController Identify] toController:[SecondViewController class]];
}

//不带参数的Routable跳转
+ (void)firstTestRoutable {
[[Routable sharedRouter] open:[FirstViewController Identify] animated:YES];
}

//带参数跳转
+ (void)secondTestRoutableWithUrlString:(NSString *)urlString {
NSDictionary *mmDict = @{ROUTE_HOME_SECOND: urlString};
[[Routable sharedRouter] open:[SecondViewController Identify] animated:YES extraParams:mmDict];
}

@end
复制代码

在准备跳转的试图里:

objective-c
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row == 0) {
[HomeRoutable firstTestRoutable];
return;
}
[HomeRoutable secondTestRoutableWithTitleString:@"哈哈哈哈哈"];
}
复制代码

在有参数传递的跳转过去的试图中 要添加下面方法

@implementation UserController

- (id)initWithRouterParams:(NSDictionary *)params {
  if (self = [super initWithRouterParams:params]) {
    self.titleString = params[ROUTE_HOME_SECOND];
  }
  return self;
}
复制代码

在这里大致介绍了怎么使用,具体细节还需要在项目里看代码实现


talk is cheap, clone the demo 快去下载项目看代码吧~~~ demo地址:http://192.168.1.209:9898/shuihuai/RoutableDemo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值