分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

通过通过url routing解决UIViewController跳转依赖

发布时间:2023-09-06 01:44责任编辑:傅花花关键词:url
???????????????????????????
???????????????????????

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跳转依赖

原文地址:https://www.cnblogs.com/llguanli/p/8523714.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved