Reputation: 203
Here is Share Button Initialized:
let shareButton = UIBarButtonItem(image: #imageLiteral(resourceName: "ShareButtonCircle"), style: .plain, target: self, action: #selector(shareButtonTapped))
Here is Objc method:
print("Share Button Clicked")
let topicTitleAndDesc = [self]
let vc = UIActivityViewController(activityItems: topicTitleAndDesc, applicationActivities: nil)
present(vc, animated: true)
viewDidLoad:
self.navigationItem.rightBarButtonItem = shareButton
Showing on screen but not performing action:
Upvotes: 0
Views: 203
Reputation: 839
I don't face any problem with below code:
override func viewDidLoad() {
super.viewDidLoad()
let shareButton = UIBarButtonItem(image: #imageLiteral(resourceName: "ShareButtonCircle"), style: .plain, target: self, action: #selector(shareButtonTapped))
self.navigationItem.rightBarButtonItem = shareButton
}
@objc func shareButtonTapped() {
print("Share Button Clicked")
let topicTitleAndDesc = [self]
let vc = UIActivityViewController(activityItems: topicTitleAndDesc, applicationActivities: nil)
present(vc, animated: true)
}
Upvotes: 1
Reputation: 16361
You are trying to share a UIViewController which is why you not getting any response. Try changing the items as follows:
let vc = UIActivityViewController(activityItems: [String(describing: self)], applicationActivities: nil)
Upvotes: 1