0

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:

screenshot

Umer Khan
  • 193
  • 12

2 Answers2

1

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)
Frankenstein
  • 15,732
  • 4
  • 22
  • 47
  • i have tried, just using print statement, button is not called objc method – Umer Khan May 06 '20 at 07:53
  • 1
    @UmerKhan If the print statement is not getting executed something else is wrong. Which cannot be found from your piece of code, need more context. – Frankenstein May 06 '20 at 08:17
1

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)
    }

RESULT HERE

Trai Nguyen
  • 809
  • 1
  • 8
  • 22