简体   繁体   English

UIActivityViewController - 没有共享选项 - Swift 5

[英]UIActivityViewController - No share options - Swift 5

I have implemented a UIActivityViewController in Swift 5 via a nav bar button and upon click this should share the contents of an array called sharedData.我已经通过导航栏按钮在 Swift 5 中实现了一个 UIActivityViewController,单击它应该共享一个名为 sharedData 的数组的内容。

When clicking the button, the share options popup is empty.单击按钮时,共享选项弹出窗口为空。

Here is my func code:这是我的函数代码:

    @IBAction func shareNavButton(_ sender: UIBarButtonItem) {
        let shareItems: [Any] = [sharedData]
        let activityVC = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
        activityVC.popoverPresentationController?.barButtonItem = sender
        self.present(activityVC, animated: true, completion: nil)
    }

Here is my entire VC code:这是我的整个 VC 代码:

class FavoritesViewController: UIViewController {

    @IBOutlet var tableView: UITableView!

    @IBAction func shareNavButton(_ sender: UIBarButtonItem) {
        let shareItems: [Any] = [sharedData]
        let activityVC = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
        activityVC.popoverPresentationController?.barButtonItem = sender
        self.present(activityVC, animated: true, completion: nil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        convertArray()
    }
}

extension FavoritesViewController: UITableViewDelegate, UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return sharedData.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.numberOfLines = 0
        cell.textLabel?.text = sharedData[indexPath.row]
        return cell
    }

    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {

        return true
    }

    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath)
        -> UISwipeActionsConfiguration? {
            let deleteAction = UIContextualAction(style: .destructive, title: "Remove") { (_, _, completionHandler) in
                sharedData.remove(at: indexPath.row)
                saveArray()
                tableView.beginUpdates()
                tableView.deleteRows(at: [indexPath], with: .automatic)
                tableView.endUpdates()
                completionHandler(true)
            }
            if #available(iOS 13.0, *) {
                deleteAction.image = UIImage(systemName: "trash")
            } else {
                // Fallback to default action
            }
            deleteAction.backgroundColor = .systemRed
            let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
            return configuration
    }

    func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let copyAction = UIContextualAction(style: .normal, title: "Copy") { (_, _, completionHandler) in

            let cell = tableView.cellForRow(at: indexPath)
            UIPasteboard.general.string = cell?.textLabel?.text

            completionHandler(true)
        }
        if #available(iOS 13.0, *) {
            copyAction.image = UIImage(systemName: "doc.on.clipboard")
        } else {
            // fall back to default action
        }
        copyAction.backgroundColor = .systemBlue
        let configuration = UISwipeActionsConfiguration(actions: [copyAction])
        return configuration
    }

}

You are using an array of string inside another array.您正在另一个数组中使用一个字符串数组。 Your sharedData is an array.您的 sharedData 是一个数组。

let shareItems: [Any] = [sharedData] 

Try with this code:试试这个代码:

let shareItems: [Any] = sharedData

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift UIActivityViewController图像共享无法正常工作 - Swift UIActivityViewController Image Share not working Swift 4 - UIActivityViewController 共享到 Outlook 主题和标题 - Swift 4 - UIActivityViewController share to Outlook Subject and Title 如何通过UIActivityViewController与Swift共享.mp3文件? - how to share a .mp3 file by UIActivityViewController with Swift? 通过在 Swift 中共享 UIActivityViewController 在电子邮件中添加主题 - Add subject on email by share UIActivityViewController in Swift 在 Swift 4 中使用 UIActivityViewController 共享 pdf 文件 - share pdf file using UIActivityViewController in Swift 4 使用UIDocumentInteractionController和UIActivityViewController时禁用共享扩展选项 - Disable Share Extension options when use UIDocumentInteractionController and UIActivityViewController 使用Swift UIActivityViewController共享来自单独的类(视图控制器)的图像? - Using Swift UIActivityViewController to share image from separate Class(viewcontroller)? 迅捷4,使用UIActivityViewController将图像共享到Facebook和其他应用程序崩溃 - swift 4, Using UIActivityViewController to share image to facebook and other app crashes 如何使用swift使用UIActivityViewController只通过电子邮件分享 - how to share only through email using UIActivityViewController using swift UIActivityViewController Gmail共享无法快速设置主题字段 - UIActivityViewController Gmail Share unable to set subject field in swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM