Question: I currently have a `UICollectionView` where I want to be able to present an `activityViewController` to enable sharing (not from a cell, but from `UIView` within the collectionView). The problem is the below code does not work because `present()` is a viewController method.

```
let activityViewController = UIActivityViewController(activityItems: [test], applicationActivities: nil)
present(activityViewController, animated:true, completion:nil)

```

I have tried creating an instance of a `viewController` to call `present()` with, however that does not work, because it isn't in the view hierarchy.

The closest thing to an answer I've found is a mention of a weak delegate, but I am not sure how to make that work.

Looking for any ideas on how to make this work. Thanks

**Update**
My hierarchy consists of a viewController `HomeViewController`, I then display a collectionView `routeDetailCollectionView` on the bottom half of the screen. Within `routeDetailCollectionView` I have a UIView `routeHeaderView` a that contains UIButton `shareButton`. I want to present the ios share menu when `shareButton` is pressed.

Answer: 
You should get `rootViewController` from `UIApplication` by using below method

```
func topMostController() -> UIViewController {
  var rootViewController: UIViewController = UIApplication.shared.keyWindow!.rootViewController!
  while (rootViewController.presentedViewController != nil) {
    rootViewController = rootViewController.presentedViewController!
  }
  return rootViewController
}

```

After that, use `rootViewController` to present `UIActivityViewController`

```
let rootViewController = topMostController()

let activityViewController = UIActivityViewController(activityItems: [test], applicationActivities: nil)
rootViewController?.present(activityViewController, animated:true, completion:nil)

```
You could use delegate to communicate with parent viewcontroller & present from there. Oru if you are using navigation controller, you can present it from there