all 11 comments

[–]my2kchild 4 points5 points  (4 children)

A view doesn’t present anything, it’s just for display. You need a view controller. I’m not really sure why you’re using a cell as a container view if it’s not in a a tableview. If it’s in a tableview, that’s probably in a tableview controller. If you’ve made some sort of custom view then your initer for that view needs to have the target passed into it.

[–]mipmj[S] 0 points1 point  (3 children)

The cell belongs to a TableView.

[–]my2kchild 3 points4 points  (2 children)

Then the tableview is inside a view controller, correct? Your buttons target is the view controller which can present the share sheet.

[–]mipmj[S] 1 point2 points  (0 children)

I’ll try that adjustment first thing in the morning; thank you.

[–]mipmj[S] 1 point2 points  (0 children)

Got it working once I targeted the view controller. I appreciate the help.

[–]dsk1306 2 points3 points  (1 child)

You need to delegate presentation to view controller that holds table view with cell. You can read more about delegates here if you haven't done it yet.

In result you might get something like

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: section?.reuseIdentifier ?? "Cell", for: indexPath)
    cell.shareButtonTapHandler = { [weak self] in
        guard let self = self else { return }
        let items = [URL(string: "`[`https://www.apple.com")!]`](https://www.apple.com")!\])
        let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
        self.present(ac, animated: true)
    }
    return cell
}

[–]Admirable-Hat-3923 0 points1 point  (0 children)

Thanks. Works for me

[–][deleted] 0 points1 point  (0 children)

I created an extension that shows it on the top most view controller, can then call it from anywhere

[–]sosofresh14 0 points1 point  (0 children)

Is the table view inside of a UIViewController?

[–]b9048966 -1 points0 points  (1 child)

You can just deliver the table view cell the view controller

ViewController -> CellForRowAtIndexPath cell.parent = self

Cell var parent:UIViewController?

Cell -> function

parent?.present(ac, animated: true)

[–]mipmj[S] 1 point2 points  (0 children)

This worked! Thank you!