Reputation: 427
I'm trying to give the user an option to share the contents of the selected tableview row via Twitter or Facebook. I've tried the following
let shareAction = UITableViewRowAction(style: .normal, title: "Share") { (action: UITableViewRowAction, IndexPath) -> Void in
let addTwitter = [UIActivityType.postToTwitter]
let firstActivityItem = self.startups[indexPath.row]
let activityViewController = UIActivityViewController(activityItems: [firstActivityItem,addTwitter], applicationActivities: nil)
self.present(activityViewController, animated: true, completion: nil)
}
Does anybody have the solution for this problem?
Upvotes: 0
Views: 111
Reputation: 40951
The activityItems
parameter should contain the things you want to share. If it's a string or URL, the system should figure out which share extensions and action extensions apply based on the context. You can get more customized.
Essentially all share targets will be enabled unless you explicitly exclude it. That means you don't need to pass in UIActivityType.postToTwitter
at all.
Just pass an array of things to share (like a String
and URL
) and Twitter should be able to figure out what you mean and the icon will be shown.
Upvotes: 1