Presenting UIActivityViewController initiating from inside UITableViewCell

1k Views Asked by At

Below code work fine and presents UIActivityViewController when put inside PostsVC (Mian View Controller) but gives cell does not have a member named 'presentViewController' error when put inside tap action of a UIButton which is placed inside UITableViewCell on the same PostsVC view controller.

How do I reference to PostsVC in the last line of code to present it ?

let appAddress =  "https://itunes.apple.com/app/id978654?ls=1&mt=8"
let shareText = "Share our app "
let activityViewController : UIActivityViewController = UIActivityViewController(activityItems: [shareText, appAddress], applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: nil)
1

There are 1 best solutions below

3
On BEST ANSWER

Add a weak reference to your view controller in your cell subclass. Set this in cellForRowAtIndexPath:

cell.viewController = self

Then call the presentViewController method on cell.viewController rather than the cell itself.