Resolve Uiviewcontroller jump dependencies by URL routing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.