Send array from custom cell to another view controller

i’m running a query to Firebase and the results are displaying in a custom cell. The cell has a UIButton that when tapped it goes to another view controller where the user can enter info. The question i have is, how do i send the array in the custom cell to the next view controller? i need to send the array so i can reference the subcollection of info i’m going to add for each array. Segue is working properly, when i print to the console, the array is empty “nil”. Any help is greatly appreciated.



Custom Cell



import UIKit
import Firebase

protocol PatCellCommentsDelegate {
func patCommentBtnTapped (ptcomments: [Comment])

class PatdataCell: UITableViewCell {

@IBOutlet weak var ptnameLbl: UILabel!
@IBOutlet weak var dobLbl: UILabel!
@IBOutlet weak var finLbl: UILabel!
@IBOutlet weak var officemdLbl: UILabel!
@IBOutlet weak var assignedmdLbl: UILabel?
@IBOutlet weak var appnameLbl: UILabel!
@IBOutlet weak var assigneddateLbl: UILabel!
@IBOutlet weak var roomnumberLbl: UILabel?
@IBOutlet weak var diagnosesLbl: UILabel!
@IBOutlet weak var reasonforadmitorconsultLbl: UILabel!
@IBOutlet weak var goalofhospitalizationLbl: UILabel!
@IBOutlet weak var seenoseeLbl: UILabel?
@IBOutlet weak var notestocboLbl: UILabel!
@IBOutlet weak var numCommentsLbl: UILabel!
@IBOutlet weak var hospitalLbl: UILabel!
@IBOutlet weak var teamLbl: UILabel!
@IBOutlet weak var addCommentBtn: UIButton!

var ptdata: PTData!
var ptcomments = [Comment]()
var delegate: PatCellCommentsDelegate?

override func awakeFromNib() {

func configurePatDataCell(ptdata: PTData, delegate: 
PatCellCommentsDelegate) {

  self.ptdata = ptdata
  self.delegate = delegate
  ptnameLbl.text = ptdata.ptname
  dobLbl.text = ptdata.dob
  finLbl.text = ptdata.fin
  officemdLbl.text = ptdata.officemd
  assignedmdLbl?.text = ptdata.assignedmd
  appnameLbl.text =
  assigneddateLbl.text = ptdata.assigneddate
  roomnumberLbl?.text =
  diagnosesLbl.text = ptdata.diagnoses
  reasonforadmitorconsultLbl.text = ptdata.reasonforadmitorconsult
  goalofhospitalizationLbl.text = ptdata.goalofhospitalization
  seenoseeLbl?.text = ptdata.seenosee
  notestocboLbl.text = ptdata.notestocbo
  numCommentsLbl.text = ptdata.comments
  hospitalLbl.text = ptdata.hosp
  teamLbl.text =


  @IBAction func addCommentBtnTapped(_ sender: Any) {

  //trying to send data to commentsVC from this cell

  delegate?.patCommentBtnTapped(ptcomments: self.ptcomments)



View Controller


import UIKit
import Firebase
import SVProgressHUD

class PatdataVC: UIViewController, UITableViewDelegate, 
UITableViewDataSource, PatCellCommentsDelegate {

@IBOutlet weak var patDataTableView: UITableView!

var ptdatas = [PTData]()
var ptComments = [Comment]()

override func viewDidLoad() {

  patDataTableView.delegate = self
  patDataTableView.dataSource = self
  patDataTableView.rowHeight = 1150


override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  if segue.identifier == "goToComments" {
  let commtsVC = segue.destination as! CommentsVC
  commtsVC.ptComments = ptComments

func tableView(_ tableView: UITableView, numberOfRowsInSection 
section: Int) -> Int {
  return ptdatas.count

func tableView(_ tableView: UITableView, cellForRowAt indexPath: 
IndexPath) -> UITableViewCell {
  if tableView == patDataTableView {
  let cell = tableView.dequeueReusableCell(withIdentifier: 
"PatdataCell", for: indexPath) as? PatdataCell
  cell!.configurePatDataCell(ptdata: ptdatas[indexPath.row], 
delegate: self)
  return cell!
  return UITableViewCell()

func patCommentBtnTapped (ptcomments: [Comment]) {

  self.ptComments = ptcomments
  performSegue(withIdentifier: "goToComments", sender: self)


Powered by WPeMatico

You may also like...

Comments are closed.