NavigationItem.rightBarButtonItem 不工作
NavigationItem.rightBarButtonItem is not working
这是已初始化的分享按钮:
let shareButton = UIBarButtonItem(image: #imageLiteral(resourceName: "ShareButtonCircle"), style: .plain, target: self, action: #selector(shareButtonTapped))
这是 Objc 方法:
print("Share Button Clicked")
let topicTitleAndDesc = [self]
let vc = UIActivityViewController(activityItems: topicTitleAndDesc, applicationActivities: nil)
present(vc, animated: true)
viewDidLoad:
self.navigationItem.rightBarButtonItem = shareButton
显示在屏幕上但不执行操作:
您正在尝试共享 UIViewController,这就是您没有收到任何响应的原因。尝试按如下方式更改项目:
let vc = UIActivityViewController(activityItems: [String(describing: self)], applicationActivities: nil)
我没有遇到以下代码的任何问题:
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
这是已初始化的分享按钮:
let shareButton = UIBarButtonItem(image: #imageLiteral(resourceName: "ShareButtonCircle"), style: .plain, target: self, action: #selector(shareButtonTapped))
这是 Objc 方法:
print("Share Button Clicked")
let topicTitleAndDesc = [self]
let vc = UIActivityViewController(activityItems: topicTitleAndDesc, applicationActivities: nil)
present(vc, animated: true)
viewDidLoad:
self.navigationItem.rightBarButtonItem = shareButton
显示在屏幕上但不执行操作:
您正在尝试共享 UIViewController,这就是您没有收到任何响应的原因。尝试按如下方式更改项目:
let vc = UIActivityViewController(activityItems: [String(describing: self)], applicationActivities: nil)
我没有遇到以下代码的任何问题:
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