JLRDemo
使用JLRoutes构建的的组件化Demo
// navigation Push规则
[JLRoutes addRoute:@"/NaviPush/:controller" handler:^BOOL(NSDictionary<NSString *,NSString *> * _Nonnull parameters) {
UIViewController *currentVc = [self currentViewController];
UIViewController *v = [[NSClassFromString(parameters[@"controller"]) alloc] init];
[self paramToVc:v param:parameters];
[currentVc.navigationController pushViewController:v animated:YES];
return YES;
}];
// StoryBoard Push规则
[JLRoutes addRoute:@"/StoryBoardPush" handler:^BOOL(NSDictionary<NSString *,NSString *> * _Nonnull parameters) {
UIViewController *currentVc = [self currentViewController];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:parameters[@"sbname"] bundle:nil];
UIViewController *v = [storyboard instantiateViewControllerWithIdentifier:parameters[@"bundleid"]];
[self paramToVc:v param:parameters];
[currentVc.navigationController pushViewController:v animated:YES];
return YES;
}];
}
-(void)paramToVc:(UIViewController *) v param:(NSDictionary<NSString *,NSString *> *)parameters{
// runtime将参数传递至需要跳转的控制器
unsigned int outCount = 0;
objc_property_t * properties = class_copyPropertyList(v.class , &outCount);
for (int i = 0; i < outCount; i++) {
objc_property_t property = properties[i];
NSString *key = [NSString stringWithUTF8String:property_getName(property)];
NSString *param = parameters[key];
if (param != nil) {
[v setValue:param forKey:key];
}
}
}