0

I am trying to send data from parent view controller to child view controller, whenever I override the performSegue method, the data loads to the popup view as shown below:

enter image description here

But what I want is show data in something like picture shown below: enter image description here

I have added the popup view to the main view from didSelectRowAt indexPath method, I used the protocol method, but it didn't load the data.

my code for parent view controller is shown below:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "customCell", for: indexPath) as! TableViewCell

    cell.customInit(noticeTitle: notificatonData[indexPath.row].notice_title,noticeDiscripetion: notificatonData[indexPath.row].notice_desc)

    return cell
}

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

    let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PopUpViewController")
    self.addChildViewController(popOverVC)
    popOverVC.view.frame = view.frame

    self.view.addSubview(popOverVC.view)
    popOverVC.didMove(toParentViewController: self)

    performSegue(withIdentifier: "goToPopUpView", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let destination = segue.destination as? PopUpViewController{
        destination.notificationfianlData = notificatonData[(tableView.indexPathForSelectedRow?.row)!]
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
TheSwiftGuy77
  • 656
  • 1
  • 9
  • 25

2 Answers2

1

You should either use segue or child

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

       performSegue(withIdentifier: "goToPopUpView", sender: self)

}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     if let destination = segue.destination as? PopUpViewController{
    destination.notificationfianlData = notificatonData[(tableView.indexPathForSelectedRow?.row)!]
}

select segue line and

enter image description here

select the main view in the popupVC and make it's background color transparent

enter image description here

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

Please try with this one. There should be no need of performSegue.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PopUpViewController")
    self.view.addSubview(popOverVC.view)
    popOverVC.notificationfianlData = notificatonData[indexPath.row]
    popOverVC.view.frame = view.bounds
}

FYI. Make PopUpViewController View, background color transparent. It will show like this.

enter image description here

PPL
  • 6,357
  • 1
  • 11
  • 30