简体   繁体   English

iOS如何将单元格数据发送到另一个VC使用Parse Swift

[英]iOS How to send cell data to another VC use parse Swift

How i can send data from my table view cell, to another VC when in tap on cell. 点击单元格时,如何将数据从表视图单元格发送到另一个VC。

My code for fetch data from DB: 我的从数据库获取数据的代码:

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

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! cellRequestsTVC

    let good = data[indexPath.row]
    name = good["username"] as! String
    cell.userNameLable.text = "@\(name)"

    area = good["place"] as! String
    cell.areaLable.text = "\(area)"

    cell.descriptionLable.text = good["description"] as? String
    cell.priorityLable.text = "Priority " + ((good["priority"] as? Int)?.description)!

    let imageProblems = good["image"] as? PFFile
    imageProblems?.getDataInBackground{ (imageData, error)in
        if imageData != nil {
            let image = UIImage(data: imageData!)
            cell.problemImage.image = image
        }
    }
    return cell
}

It's working perfect. 工作正常。 But now my target open data from cell in another VC. 但是现在我的目标是从另一个VC中的单元打开数据。 Example: 例:

Example

You have to implement UITableViewDelegate 您必须实现UITableViewDelegate

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let good = data[indexPath.row]
// Here you can either perform a segue or push view controller to UINavigationController

//Push View controller 

    let storyBoard : UIStoryboard =  UIStoryboard(name: "Main", bundle: nil)
    let vc : DetailViewController = storyBoard.instantiateViewController(withIdentifier: "DetailViewController") as! DetailViewController
    vc.sharedData = data // here you pass data
    self.navigationController?.pushViewController(vc, animated: true)

}

In DetailViewController create object of data with required type DetailViewController创建具有所需类型的数据对象

var sharedData : [String : Any]! // Take optional variable if object can be nil & here assuming data contains object of type [String : Any]

You can look the documentation here UITableViewDelegate 您可以在此处查看文档UITableViewDelegate

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM