简体   繁体   English

与Peek和Pop共享表

[英]Share Sheet with Peek and Pop

I am trying to get a share sheet to come up after and action button is tapped on the the peek and pop action item. 我正在尝试显示一个共享表,然后在“查看”和“弹出”操作项上点击“操作”按钮。 The problem is that the share sheet is has to come up from a specified VC. 问题是必须从指定的VC中创建共享表。 In a normal VC, I would just say self. 在普通的VC中,我只会说自己。 But in this case, once the action item is tapped, the vc that we would normally present the share sheet from gets dismissed. 但是在这种情况下,一旦点击了操作项,我们通常会从中显示股份单的vc就被取消了。 That is just how action items work with peek and pop. 这就是动作项如何与peek和pop一起工作的方式。 How do I tell the share sheet to present from the original VC or VC below it? 我如何告诉股份单从原始的VC或下面的VC呈现?

Here is the code for the share sheet. 这是共享表的代码。

//This is in the function createShareSheet
branchUniversalObject.showShareSheet(with: linkProperties, andShareText: "Check out this post!", from: self) { (string, bool) in
    print ("done")
}

and here is the code for the action item: 这是操作项的代码:

override var previewActionItems: [UIPreviewActionItem] {
    let action2 = UIPreviewAction(title: "Share", style: .default, handler: { previewAction, viewController in

        //This basically gives data to the function that has the above code for creating the share sheet.
        self.createShareSheet(self.selectedItem!)
        return [action2]
    })

You haven't provided enough code for me to give an exact solution, but basically you will need to pass your "current" view controller to the "peek" view controller so that it can use it to present the share sheet. 您没有为我提供足够的代码来提供确切的解决方案,但是基本上您将需要将“当前”视图控制器传递给“窥视”视图控制器,以便它可以使用它来显示共享表。

Something like: 就像是:

func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {

    guard let detailVC = storyboard?.instantiateViewController(withIdentifier: "DetailViewController") as? DetailViewController else { return nil }

    detailVC.rootVC = self

    return detailVC
}

Now you can use the rootVC property in your peek action handler to present the share sheet from the right vc 现在,您可以在peek动作处理程序中使用rootVC属性,以显示来自右侧vc的共享表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM