Capturing cell values outside of cellForRowAt

I want to access some cell values outside of cellForRowAt.

  @IBAction func ShareClicked(_ sender: UIButton) -> Void {
        print("Hello Edit Button")

        let indexPath = IndexPath(row: 0, section: 0)
        let cell = TableView.cellForRow(at: indexPath) as! ProfileTableViewCell

        let activityVC = UIActivityViewController(activityItems: [cell.Books!, "I found this book", cell.Title!,"in the LitSwap app for :",cell.Price! ], applicationActivities: nil)
        activityVC.popoverPresentationController?.sourceView = self.view

        self.present(activityVC, animated: true, completion: nil)


I want to access cell.Books, cell.Title and cell.Price in a button function. However, with my solution above, I want to be able to capture any row in my tableViewCell and not just (row: 0, section: 0) but I am not sure how to do that.

1 answer

  • answered 2017-06-17 19:51 Arthi

    In the cellforRowAtIndexPath, update the tag of button to the indexpath.row, And in the button action method retrieve the data from the model based on the tag..