XYRouter

https://github.com/uxyheaven/XYRouter

XYRouter是一个通过url routing来解决UIViewController跳转依赖的类.

* 本类採用ARC

Installation

  • 本库基于ARC
  • 拷贝XYQuick到项目里
  • 在须要用的文件或者pch里 #import "XYRouter.h"

Podfile

pod 'XYRouter'

#import "XYRouter.h"

Usage

Creating viewController map

能够通过key和NSString来映射一个UIViewController

[[XYRouter sharedInstance] mapKey:@"aaa" toControllerClassName:@"UIViewController"];

Getting viewController for key

当取出ViewController的时候, 假设有单例[ViewController sharedInstance], 默认返回单例, 假设没有, 返回[[ViewController alloc] init].

UIViewController *vc = [[XYRouter sharedInstance] viewControllerForKey:@"aaa"];

Maping a viewController instance

假设不想每次都创建对象, 也能够直接映射一个实例

[[XYRouter sharedInstance] mapKey:@"bbb" toControllerInstance:[[UIViewController alloc] init]];

Maping a viewController instance with a block

假设想更好的定制对象, 能够用block

[[XYRouter sharedInstance] mapKey:@"nvc_TableVC" toBlock:^UIViewController *{
TableViewController *vc = [[TableViewController alloc] init];
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
return nvc;
}];

Opening path

你能够使用key去push出一个viewController

[[XYRouter sharedInstance] openUrlString:@"aaa"];

path还支持相对路径, 如以下的代码能够在当前文件夹下push出一个TableVC后, 再push出TestVC1.

[[XYRouter sharedInstance] openUrlString:@"./TableVC/TestVC1"];

眼下支持这些描写叙述:

  • 在当前文件夹push ./
  • 在上一个文件夹push ../
  • 在根文件夹根push /

Assigning parameters

在跳转的时候还能够传递參数

@interface TestVC1 : UIViewController
@property (nonatomic, assign) NSInteger i;
@property (nonatomic, copy) NSString *str1;
@property (nonatomic, copy) NSString *str2;
@end [[XYRouter sharedInstance] openUrlString:@"TestVC1?str1=a&str2=2&i=1"];

Changing rootViewController

能够用scheme:window替换windows.rootViewController

// rootViewController : nvc_TableVC
[[XYRouter sharedInstance] openUrlString:@"window://nvc_TableVC/TestVC1"];

Presenting rootViewController

能够用scheme:modal来呈现一个模态视图

// rootViewController : nvc_TableVC
[[XYRouter sharedInstance] openUrlString:@"modal://nvc_TableVC/TestModalVC/"]; // rootViewController : TestModalVC
[[XYRouter sharedInstance] openUrlString:@"modal://TestModalVC/?str1=a&str2=2&i=1"];

Dismissing rootViewController

关闭这个模态视图直接用dismiss

[[XYRouter sharedInstance] openUrlString:@"dismiss"];

通过通过url routing解决UIViewController跳转依赖的更多相关文章

  1. 转:【WebDriver】封装GET方法来解决页面跳转不稳定的问题

    在大多数测试环境中,网络或者测试服务器主机之间并不是永远不出问题的,很多时候一个客户端的一个跳转的请求会因为不稳定的网络或者偶发的其它异常hang死在那里半天不动,直到人工干预动作的出现.      ...

  2. [ASP.NET MVC 小牛之路]07 - URL Routing

    我们知道在ASP.NET Web Forms中,一个URL请求往往对应一个aspx页面,一个aspx页面就是一个物理文件,它包含对请求的处理. 而在ASP.NET MVC中,一个URL请求是由对应的一 ...

  3. ASP.NET MVC 学习之路由(URL Routing)

    在ASP.NET MVC中,一个URL请求是由对应的一个Controller中的Action来处理的,由URL Routing来告诉MVC如何定位到正确的Controller和Action. 默认路由 ...

  4. URL Routing

    们知道在ASP.NET Web Forms中,一个URL请求往往对应一个aspx页面,一个aspx页面就是一个物理文件,它包含对请求的处理. 而在ASP.NET MVC中,一个URL请求是由对应的一个 ...

  5. 控制器 - URL routing HTTP module(一)

    URL routing HTTP module 负责处理检查入站请求的 URL,并将它们分派到最合理的处理器上.URL routing HTTP module 也替代了旧版本的 ASP.NET URL ...

  6. 【ASP.NET MVC 学习笔记】- 08 URL Routing

    本文参考:http://www.cnblogs.com/willick/p/3343105.html 1.URL Routing告诉MVC如何正确的定位Controller和Action. 2.URL ...

  7. ios访问web页面<div>点击事件不起效果,以及alert()显示url的解决办法

    ios访问web页面<div>点击不起效果,在其div上添加style=”cursor:pointer:“ jquery web页面动态append()事件调用方法:$(document) ...

  8. [译]Angular-ui 之 Url Routing

    ◄ 前一篇 (Multiple Named Views)     下一篇 (The Components) ► 在你的应用中多数的状态都是基于特定的url地址的.Url Routing机制绝不是在状态 ...

  9. spring如何解决单例循环依赖问题?

    更多文章点击--spring源码分析系列 1.spring循环依赖场景2.循环依赖解决方式: 三级缓存 1.spring循环引用场景 循环依赖的产生可能有很多种情况,例如: A的构造方法中依赖了B的实 ...

随机推荐

  1. 深入理解Spring IoC容器和动态代理机制

    Deployment期间验证 实现一: <bean id="theTargetBean" class="..."/> <bean id=&qu ...

  2. [模板] Exgcd

    求解一组ax+bc=gcd(a,b) #include<iostream> #include<cstdio> using namespace std; int exgcd(in ...

  3. InnoDB INFORMATION_SCHEMA Lock Tables

    InnoDB INFORMATION_SCHEMA Lock Tables 三张InnoDB INFORMATION_SCHEMA表使您能够监视事务并诊断潜在的锁定问题: INNODB_TRX:提供有 ...

  4. xshell连接Linux(centos6.8)失败的解决方法

    注意:本人使用的是Centos6.8版本. Centos7以上版本linux命令会又不一样的地方. 启动xshell终端进行连接服务器:使用命令:ssh + ip地址或是手动使用可视化操作窗口操作, ...

  5. day15-python之变量和递归

    1.局部变量与全局变量 #!/usr/bin/env python # -*- coding:utf-8 -*- # name='lhf' # def change_name(): # global ...

  6. 【MVC 2】MVC+EF框架结构实例:注册ID号验证

    导读:本篇博客,将通过一个实例,详细介绍MVC+EF的应用.原理性的东西或者说是进一步的解耦和,请看博客: [框架结构 3]MVC+EF实体框架-原理解析.在这里,仅用MVC框架和一个EF生成的Mod ...

  7. centos配置mutt跟msmtp发送邮件

    一.安装mutt yum install mutt 二.配置mutt vi /etc/Muttrc 在里面找到下面几行,并将内容修改为你自己的内容(下面几行分布在不同位置,请耐心查找,记得去掉它行首的 ...

  8. iOS-runtime-objc_setAssociatedObject(关联对象以及传值)

    例子: static const char kRepresentedObject; - (IBAction)doSomething:(id)sender { UIAlertView *alert = ...

  9. 七牛云赵之健:多维度融合赋能视频 AI 的实践

    6 月 30 日下午,赵之健在七牛架构师实践日第二十九期进行了<多维度融合赋能视频 AI 的实践>为题的实战分享. 
 作者简介: 
  赵之健,七牛人工智能实验室资深算法工程师, 七 ...

  10. HDU 1358 next数组的推移

    题目大意: 输入n,再输入一个长度为n的字符串,从第二位开始,计算它的前缀(包括他自己)中出现过的重复字符串的个数,如aabaabaabaab的第6位的前缀aabaab,aab连续出现了两次,所以输出 ...