适用于iOS的URL路由框架
这是一个典型的方式导航通过视图控制器
#import "MyViewController.h"
...
MyViewController *controller = [[MyViewController alloc] init];
controller.someProperty = someProperty;
controller.someOtherProperty = someOtherProperty
[self.navigationController pushViewController:controller
animated:YES];
这是同样的工作用路由器来完成。
[[PRRouter defaultRouter] openURL:myModel.url
withNavigationController:self.navigationController];
使用路由器的优势
@implementation PRUserViewController
...
#pragma mark - Life cycle
+ (void)load
{
[[PRRouter defaultRouter] mapPath:@"/user/:user_id"
toControllerClass:self];
}
...
@end
-initWithParams:query:fragment:
@implementation PRUserViewController
...
- (instancetype)initWithParams:(NSDictionary *)params
query:(NSDictionary *)query
fragment:(NSString *)fragment
{
self = [super initWithParams:params
query:query
fragment:fragment];
if (self) {
// Initialize your view controller
}
return self;
}
...
@end
@implementation PRContactsViewController
...
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
PRContact *contact = self.viewModel.objects[indexPath.row];
[[PRRouter defaultRouter] openURL:contact.url
withNavigationController:self.navigationController];
}
...
@end
见 文档.
本项目按照MIT许可证的条款和条件发布。有关详细信息,请参阅 许可文件
本项目由 Elethom Hunter 设计和开发。您可以通过以下方式联系我:
您可以通过以下方式支持我:
:-)