zoukankan      html  css  js  c++  java
  • 应用间跳转和传值

    1.首先设置第一个应用的的 URL:

    2.然后设置第二个应用的的 URL:

     
    3.需要跳转的时候(可以直接填写urlString为AppJumpSecond:”,拼接//%@就可以实现传值
    NSString *urlString = [NSString stringWithFormat:@"AppJumpSecond://%@",textField.text];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
     
    我这里将textField的文字也传过去。
     
    同样的,在第二个页面也是如此。
     
    NSString *urlString = [NSString stringWithFormat:@"AppJumpFirst://%@",textField.text];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
     
    这样就能相互跳转了,并且实现了传值。
     

    4.处理传过去的数据

    在上面传了textField的数据,接收时在AppDelegate的

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation方法里。

    在AppDelegate里设置属性

    @property (nonatomic, strong) RootViewController *rvc;

     
    在didFinishLaunchingWithOptions方法里添加
     
    self.rvc = [[RootViewController alloc] init];
    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:self.rvc];
    self.window.rootViewController = nc;
     
    添加代码块
     
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    {
        self.rvc.textField.text = [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        return YES;
    }
     
    使得textField显示另一个页面传过来的数据。
  • 相关阅读:
    java面试总结之框架问题
    数据库设计三大范式
    js 一些技巧
    el 和 fmt 常用
    iframe自适应高度
    MySQL基础
    任意精度整数算法 (BigInteger) 和任意精度小数算法 (BigDecimal)
    hibernate
    Struts2
    Servlet、Cookie、Session
  • 原文地址:https://www.cnblogs.com/xiu619544553/p/5194994.html
Copyright © 2011-2022 走看看