简体   繁体   English

将tableview所选数据共享到Whats App

[英]share tableview selected data to whats app

i am sharing data on whats app which is selected on tableview so i have two option to select tableview rows One is Select All and another is on didSelect so when i select all then share is work perfect and i am sharing encoded data here is my data for sharing all tableview data 我正在共享在tableview上选择的应用程序上的数据,所以我有两个选择来选择tableview行的一个是全选,另一个是在didSelect上,所以当我全选时,共享是完美的工作,我在这里共享编码数据用于共享所有tableview数据

Code Of My struct model 我的结构模型代码

class QuotationListDataModel: Encodable{
    var id: String?
    var quantity: String?
    var margin: String?
    var part_number: String?
    var total_price: String?
    var freight: String?

    init(id: String?,quantity: String?,margin: String?,part_number: String,total_price: String,freight: String) {
        self.id = id
        self.quantity = quantity
        self.margin = margin
        self.part_number = part_number
        self.total_price = total_price
        self.freight = freight
    }
}

here is my api form with i am getting data 这是我正在获取数据的api表格

var quotationSeelctedData = [QuotationListDataModel]()

func quotationListAPI(){
    let preferences = UserDefaults.standard
    let uid = "u_id"
    let acTkn = "acc_tkn"

    let u_ID = preferences.object(forKey: uid)
    let A_Token = preferences.object(forKey: acTkn)

    let params = ["user_id": u_ID!, "access_token": A_Token!]
    print(params)
    self.viewMainSpinner.isHidden = false
    self.viewInnerSpinner.startAnimating()
    Alamofire.request(quatationlist, method: .post, parameters: params).responseJSON(completionHandler: {(response) in
        switch response.result{
        case.success(let value):
            let json  = JSON(value)
            print(json)
            let data = json["quation_list"]
            print(data)
            if data == []{
                self.viewMainSpinner.isHidden = true
                self.viewInnerSpinner.stopAnimating()
            }else{
                data.array?.forEach({ (qList) in
                    let id = qList["id"].stringValue
                    let quantity = qList["quantity"].stringValue
                    let margin = qList["margin"].stringValue
                    let part_number = qList["part_number"].stringValue
                    let total_price = qList["total_price"].stringValue
                    let freight = qList["freight"].stringValue
                    self.quotationSeelctedData.append(QuotationListDataModel(id: String(describing: id), quantity: String(describing: quantity), margin: String(describing: margin), part_number: String(describing: part_number), total_price: String(describing: total_price), freight: String(describing: freight)))
                })
                self.tblListView.reloadData()
                self.viewMainSpinner.isHidden = true
                self.viewInnerSpinner.stopAnimating()
            }
        case.failure(let error):
            print(error.localizedDescription)
            self.viewMainSpinner.isHidden = true
            self.viewInnerSpinner.stopAnimating()
        }

    })
}

so i am storing all data in quotationSeelctedData and encode like below 所以我将所有数据存储在quotationSeelctedData并如下编码

    let encoder = JSONEncoder()
    encoder.outputFormatting = .prettyPrinted
    do {
        let jsonData = try encoder.encode(quotationSeelctedData)
        if let jsonString = String.init(data: jsonData, encoding: .utf8) {
            print(jsonString)
            let stringwithoutquotes = jsonString.replacingOccurrences(of: "{", with: "")
            let removebracket1 = stringwithoutquotes.replacingOccurrences(of: "}", with: "")
            let removebracket2 = removebracket1.replacingOccurrences(of: "[", with: "")
            let removebracket3 = removebracket2.replacingOccurrences(of: "]", with: "")
            self.jsString = removebracket3
        }
    } catch {
        print("the encoding failed")
    }

with upper code i am encode data in which store in quotationSeelctedData array 使用上位代码,我对存储在quotationSeelctedData数组中的数据进行编码

so now when there is no data selected in tableview and with didSelect click i am select only one data and share only selected data so please help me how to share only selected data to whats app 所以现在当在表视图中没有选择数据并且使用didSelect单击时,我仅选择一个数据并仅共享选择的数据,所以请帮助我如何仅将选择的数据共享到whats应用程序

i mean to say is that is just want to share selected data so please tell me how to store data in array on did select 我的意思是说那只是想共享选定的数据,所以请告诉我如何将数据存储在没有选择的数组中

i am sharing data in whats app like below 我在下面的Whats App中共享数据

  "quantity" : "1000000000",
    "id" : "14",
    "freight" : "999",
    "total_price" : "422730",
    "margin" : "999",
    "part_number" : "15"
  ,

    "quantity" : "123456789123456789",
    "id" : "13",
    "freight" : "123456789123456789",
    "total_price" : "52965736795102108",
    "margin" : "123456789123456789",
    "part_number" : "15"
  ,

    "quantity" : "150",
    "id" : "12",
    "freight" : "15",
    "total_price" : "4186",
    "margin" : "4",
    "part_number" : "15"
  ,

    "quantity" : "150",
    "id" : "11",
    "freight" : "15",
    "total_price" : "4186",
    "margin" : "4",
    "part_number" : "15"
  ,

    "quantity" : "100",
    "id" : "10",
    "freight" : "10",
    "total_price" : "3927.0",
    "margin" : "2",
    "part_number" : "15"
  ,

    "quantity" : "12",
    "id" : "9",
    "freight" : "15",
    "total_price" : "4105.5",
    "margin" : "2",
    "part_number" : "19"
  ,

    "quantity" : "100",
    "id" : "8",
    "freight" : "10",
    "total_price" : "3927.0",
    "margin" : "2",
    "part_number" : "17"
  ,

    "quantity" : "100",
    "id" : "7",
    "freight" : "10",
    "total_price" : "3927.0",
    "margin" : "2",
    "part_number" : "15"
  ,

    "quantity" : "150",
    "id" : "6",
    "freight" : "101",
    "total_price" : "15547.35",
    "margin" : "121",
    "part_number" : "20"
  ,

    "quantity" : "100",
    "id" : "5",
    "freight" : "10",
    "total_price" : "3927.0",
    "margin" : "2",
    "part_number" : "19"
  ,

    "quantity" : "100",
    "id" : "4",
    "freight" : "10",
    "total_price" : "0.0",
    "margin" : "2",
    "part_number" : "17"
  ,

    "quantity" : "100",
    "id" : "3",
    "freight" : "10",
    "total_price" : "3927.0",
    "margin" : "2",
    "part_number" : "20"
  ,

    "quantity" : "100",
    "id" : "2",
    "freight" : "10",
    "total_price" : "3927.0",
    "margin" : "2",
    "part_number" : "15"
  ,

    "quantity" : "2",
    "id" : "1",
    "freight" : "20",
    "total_price" : "1230",
    "margin" : "30",
    "part_number" : "15"
let yourDataModel = [QuotationListDataModel]

get data from the selected tableViewCell : 从选定的tableViewCell获取数据:

    func tableView(_ tableView: UITableView, 
         didSelectRowAt indexPath: IndexPath){

    let dataToBeSent = yourDataModel[indexPath.row] 

    // share this data in whatsApp using UIActivityViewController:

    let items = [dataToBeSent]
    let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)

    present(activityViewController, animated: true)

  }

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

相关问题 在watchOS4中从Apple Watch应用程序到iPhone应用程序共享实时数据的最佳方法是什么? - Whats the best way to share real time data from an apple watch app to iphone app in watchOS4? 在不显示 ActionSheet 的情况下将视频分享到 whats 应用程序 - share videos to whats app without showing ActionSheet 在Whats App上共享App Store和Play商店链接 - Share on whats app both App Store and Play store links UIActivityViewController在whats app和所有共享选项中共享文本 - UIActivityViewController Share text in whats app and all sharing option iOS App Store:如何共享所选 App Store/地区的分析数据? - iOS App Store: How to share analytics data of selected App Store / region? 根据选择的TableView单元格加载数据 - Load Data depending on what TableView Cell was selected 将tableview选择的数据存储到具有键值的数组中 - store tableview selected data into array with key value 重新启动应用后,tableview不会在tableview中显示所有数据 - tableview does not show all the data in tableview after restart of app 如何使已选择为Vine App的无颜色的Tableview单元格 - How to make the tableview cell that has been selected to no color as Vine App ios 应用程序不显示表格视图中的数据 - ios app does not show the data in the tableview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM