美文网首页
DCURLrouter

DCURLrouter

作者: wpf_register | 来源:发表于2016-08-29 23:33 被阅读502次

    到网上看到自定义URL实现控制器间跳转,觉得很有意思,尝试了一下,确实有意思,记录一下。
    原文地址

    1. 将DCURLRouter文件夹拖到项目中
    2. 配置DCURLRouter.plist文件


    3. 加载DCURLRouter.plist文件数据
    [DCURLRouter loadConfigDictFromPlist:@"DCURLRouter.plist"];
    
    1. push
     // 不需要拼接参数直接跳转
     [DCURLRouter pushURLString:@"dariel://twoitem" animated:YES];
     
     // 直接把参数拼接在自定义url末尾
     NSString *urlStr = @"dariel://twoitem?name=dariel&userid=213213";
     [DCURLRouter pushURLString:urlStr animated:YES];
     // 可以将参数放入一个字典
     NSDictionary *dict = @{@"userName":@"Hello", @"userid":@"32342"};
     [DCURLRouter pushURLString:@"dariel://twoitem" query:dict animated:YES];
     
     // 如果当前控制器和要push的控制器是同一个,可以将replace设置为Yes,进行替换.
     [DCURLRouter pushURLString:@"dariel://oneitem" query:dict animated:YES replace:YES];
     
     // 重写了系统的push方法,直接通过控制器跳转
     TwoViewController *two = [[TwoViewController alloc] init];
     [DCURLRouter pushViewController:two animated:YES];
    

    modal

    // 不需要拼接参数直接跳转
     [DCURLRouter presentURLString:@"dariel://threeitem" animated:YES completion:nil];
     
     // 直接把参数拼接在自定义url末尾
     NSString *urlStr = @"dariel://threeitem?name=dariel&userid=213213";
     [DCURLRouter presentURLString:urlStr animated:YES completion:nil];
     
     // 可以将参数放入一个字典
     NSDictionary *dict = @{@"userName":@"Hello", @"userid":@"32342"};
     [DCURLRouter presentURLString:@"dariel://threeitem" query:dict animated:YES completion:nil];
     
     // 给modal出来的控制器添加一个导航控制器
     [DCURLRouter presentURLString:@"dariel://threeitem" animated:YES withNavigationClass:[UINavigationController class] completion:nil];
     
     // 重写了系统的push方法
     ThreeViewController *three = [[ThreeViewController alloc] init];
     [DCURLRouter presentViewController:three animated:YES completion:nil];
    
    1. pop/dismiss
       /** pop掉一层控制器 */
        + (void)popViewControllerAnimated:(BOOL)animated;
        /** pop掉两层控制器 */
        + (void)popTwiceViewControllerAnimated:(BOOL)animated;
        /** pop掉times层控制器 */
        + (void)popViewControllerWithTimes:(NSUInteger)times animated:(BOOL)animated;
        /** pop到根层控制器 */
        + (void)popToRootViewControllerAnimated:(BOOL)animated;
    
       /** dismiss掉1层控制器 */
        + (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion;
        /** dismiss掉2层控制器 */
        + (void)dismissTwiceViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion;
        /** dismiss掉times层控制器 */
        + (void)dismissViewControllerWithTimes:(NSUInteger)times animated: (BOOL)flag completion: (void (^ __nullable)(void))completion;
        /** dismiss到根层控制器 */
        + (void)dismissToRootViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion;
    

    相关文章

      网友评论

          本文标题:DCURLrouter

          本文链接:https://www.haomeiwen.com/subject/wurfettx.html