【问题标题】:Issues presenting UIActivityViewController呈现 UIActivityViewController 的问题
【发布时间】:2014-04-16 10:53:32
【问题描述】:

我想在我的应用中提供一个共享屏幕。我为此目的使用UIActivityViewController。问题是,根据您在应用程序中的位置,当前的根视图控制器可以是UINavigationController(Case1) 或UIViewController(Case2)。

我可以使用 UIActivityViewController 展示

[viewController presentViewController:viewController animated:YES completion:nil];

但我必须在 (Case1) 中获取当前可见的 UIViewControllerUINavigationController,并在 (Case2) 中获取根视图控制器本身。

但是如何检测存在哪种根视图控制器并相应地编码?

谢谢。

【问题讨论】:

    标签: ios uiactivityviewcontroller


    【解决方案1】:

    试试:

    UIViewController *root = [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] nextResponder];
    

    然后:

    if ([root isKindOfClass:[UINavigationController class]]) {
        // Navigation Controller
    } else {
        // The other one
    }
    

    这应该告诉你呈现的是哪一个。

    【讨论】:

    • 使用 [root presentViewController:viewController animated:YES completion:nil] 给出错误警告:尝试在 <_uimodalitemappviewcontroller:> 上呈现 已经呈现 <_uimodalitemspresentingviewcontroller:>跨度>
    • 那是因为你在关闭一个 VC 后过早地显示了一个 VC。将前一个的解除放在完成处理程序中,完成后,呈现新的。
    • 对不起,我没明白你的意思。我在 UINavigationController 上模态地展示 UIViewController。然后用户点击一个我称之为 UIActivityViewController 的按钮。所以似乎没有过渡问题,因为它已经完成了。
    • 重点是,我发布的代码不是导致错误弹出的问题。出现错误的原因有很多 - 转换错误、IBAction 链接错误或模态 VC 呈现错误(例如呈现两次)。
    • 您是否使用pushViewController:animated 和 UINavigationController 来显示 UIViewControllers?或者也许我错过了一些东西。当您说“根视图控制器本身”时,您是说导航控制器将被删除附加到keyWindow 的视图层次结构?
    【解决方案2】:

    使用上述方法检测是否有 UINavigationControler;

     - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
    //If this will be called it is a navigation controller
    }
    

    【讨论】:

      【解决方案3】:

      使用 performselector 启动和停止旋转活动指示符

      这里的 AI 是活动指示变量名称

          [self performSelector:@selector(animateAI) withObject:self afterDelay:0.1];
      
          [self performSelector:@selector(stopAI) withObject:self afterDelay:0.9];
      
      -(void)animateAI
      {
          [AI startAnimating];
      
      }
      
      -(void)stopAI
      {
         [AI stopAnimating];
      }
      

      【讨论】:

      • 问题是关于UIActivityViewController。你说的是UIActivityIndicatorView不同的东西。
      猜你喜欢
      • 2015-09-05
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 2012-10-05
      • 2014-05-10
      • 1970-01-01
      相关资源
      最近更新 更多