【问题标题】:transitionViewForCurrentTransition is not set, presentation controller was dismissed during the presentation未设置 transitionViewForCurrentTransition,演示控制器在演示期间被关闭
【发布时间】:2017-04-01 14:36:16
【问题描述】:

TransitionViewForCurrentTransition 未设置,演示控制器在演示期间被关闭? (<_uifullscreenpresentationcontroller> 怎么解决,打印没有异常,但调用时显示以上错误

-(IBAction)presume:(id)sender
{
        [self returnToRootViewController];

}



 - (UIViewController*)topmostViewController
    {
        UIViewController* vc = [[[UIApplication sharedApplication] keyWindow] rootViewController];
        while(vc.presentedViewController) {
            vc = vc.presentedViewController;
        }
        return vc;
    }

    - (void)returnToRootViewController
    {
        UIViewController* vc = [self topmostViewController];
        while (vc) {
            if(vc.presentingViewController) {
                if ([vc isKindOfClass:[CarDetailVC class]])
                {

                    @try {



                        [vc dismissViewControllerAnimated:NO completion:^{}];

                    } @catch (NSException *exception) {

                        NSLog(@"exception=%@",exception);
                    } @finally {

                    }


                 }

            }
            vc = vc.presentingViewController;
        }



    }

【问题讨论】:

  • 我看到了这里与您之前的问题的关系。您是否只想解雇直到 CarDetailVC 位于顶部?这可以更直接地完成
  • 是的,我尝试了上述解决方案并坚持使用它

标签: ios objective-c uiviewcontroller


【解决方案1】:

让我们从指向目标 vc(CarDetailVC 的实例)的更直接路径开始。

- (UIViewController*)vcWithClass:(Class)klass {
    UIViewController* vc = [[[UIApplication sharedApplication] keyWindow] rootViewController];
    while(![vc.presentedViewController isKindOfClass:klass]) {
        vc = vc.presentedViewController;
    }
    return vc;
}

现在,开始处理它并关闭它呈现的 vc。

- (void)returnToCarVC {
    CarDetailVC *carVC =(CarDetailVC*) [self vcWithClass:[CarDetailVC self]];
    UIViewController *presented = carVC.presentedViewController;
    [presented dismissViewControllerAnimated:NO completion:^{}];
}

【讨论】:

  • 警告在不兼容的指针类型初始化 CarDetailVC * 的表达式为 UIViewcontroller CarDetailVC *carVC = [self vcWithClass:[CarDetailVC self]];
  • 不再靠近开发机器,但那是次要的:只需转换结果*carVC = (CarDetailVC)...
  • 感谢丹,您不仅节省了我的一天,还节省了整个周末。
猜你喜欢
  • 2021-06-22
  • 1970-01-01
  • 2011-05-18
  • 1970-01-01
  • 1970-01-01
  • 2011-03-02
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多