Xyrouter
Https://github.com/uxyheaven/XYRouter
Xyrouter is a class that resolves Uiviewcontroller jump dependencies through URL routing.
* This class uses arc
Installation
- This library is based on arc
- Copy the Xyquick into the project.
- In a file you need or a PCH.
#import "XYRouter.h"
Podfile
‘XYRouter‘#import "XYRouter.h"
Usagecreating Viewcontroller Map
A uiviewcontroller can be mapped by key and NSString.
[[XYRouter sharedInstance]mapKey:@"aaa" toControllerClassName:@"UIViewController"];
Getting Viewcontroller for key
When removing the Viewcontroller, if there is a singleton [Viewcontroller sharedinstance], the default is to return to the singleton, if not, return [[Viewcontroller alloc] init].
UIViewController *vc = [[XYRouter sharedInstance] viewControllerForKey:@"aaa"];
Maping a Viewcontroller instance
If you don't want to create an object every time, you can also map an instance directly
[[XYRouter sharedInstance]mapKey:@"bbb" toControllerInstance:[[UIViewController alloc] init]];
Maping a Viewcontroller instance with a block
If you want a better custom object, you can use block
[[XYRouter sharedInstance] mapKey:@"nvc_TableVC" toBlock:^UIViewController *{ TableViewController *vc = [[TableViewController alloc] init]; UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc]; return nvc; }];
Opening Path
You can use key to push out a Viewcontroller
[[XYRouter sharedInstance] openUrlString:@"aaa"];
Path also supports relative paths, as the following code can push out a TABLEVC in the current directory and then push out TestVC1.
[[XYRouter sharedInstance] openUrlString:@"./TableVC/TestVC1"];
These descriptions are currently supported:
- In the current directory push
./
- On the previous directory push
../
- Root push in root directory
/
Assigning parameters
You can also pass parameters when jumping.
@interface TestVC1 : UIViewController@property (nonatomicassignNSInteger i;@property (nonatomicNSString *str1;@property (nonatomicNSString *str2;@end[[XYRouter sharedInstance] openUrlString:@"TestVC1?str1=a&str2=2&i=1"];
changing Rootviewcontroller
Can replace Windows.rootviewcontroller with Scheme:window
// rootViewController : nvc_TableVC[[XYRouter sharedInstance] openUrlString:@"window://nvc_TableVC/TestVC1"];
Presenting Rootviewcontroller
You can use Scheme:modal to render a modal view
// 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
Close this modal view directly with dismiss
[[XYRouter sharedInstance] openUrlString:@"dismiss"];
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Resolve Uiviewcontroller jump dependencies by URL routing