PRRouter 0.2

PRRouter 0.2

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
发布最后发布2016年5月

Elethom Hunter 维护。



适用于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];

使用路由器的优势

  • 更少的耦合和更灵活
  • 服务器端可以控制导航逻辑
  • 通过回退到web视图提供更好的向后兼容性

安装

入门

将路径映射到视图控制器类

@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

使用URL导航到视图控制器

@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

完整API参考

文档.

许可证

本项目按照MIT许可证的条款和条件发布。有关详细信息,请参阅 许可文件

联系我们

本项目由 Elethom Hunter 设计和开发。您可以通过以下方式联系我:

社交

捐赠

您可以通过以下方式支持我:

:-)