0

i have two viewcontrollers: One which is just normal and the other one which i use like a Popup Viewcontroller. Now i need to pass a value to the Popup Viewcontroller but i cannot do it with the normal prepare for segue method. I start showing the Popup Controller like this:

  let popUpPreload = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "selectShoppingList") as! AddToListViewController

    self.addChild(popUpPreload)
    popUpPreload.view.frame = self.view.frame
    self.view.addSubview(popUpPreload.view)

    popUpPreload.didMove(toParent: self)

so how can i transfer a value to my Subview

jscs
  • 63,694
  • 13
  • 151
  • 195

2 Answers2

1

You need

popUpPreload.someProperty = ""
self.addChild(popUpPreload)

class AddToListViewController:UIViewController {
   var someProperty:String?
   //........ access someProperty inside viewDidLoad
} 
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

You can add subview within your first view controller as per shown in image. Add one label where you want to show your data I think you don't need to move to next viewController you can do this from single viewController as Add Sub view on same screen.

 @IBAction func buttonSave(_ sender: UIButton) {

            self.subViewLabel.text = textFieldName.text
            self.view.addSubview(subView)
        }


        @IBAction func crossBtnAction(_ sender: UIButton) {
            self.subView.removeFromSuperview()
        }
Deviyani Swami
  • 749
  • 8
  • 17