kevin-lyn/STPopup

How to pass data to a popup?

Aleph72 opened this issue · 2 comments

I haven't found any way to pass some data to the popup, is it even possible?
For example, I need to pass an array to the popup, so I can populate a tableView with data, then, upon selecting a row, some other data should be passed back to the view containing the popup.

Hi, @Aleph72 You can pass array as following:

For eg.
here PopUpTableView is the view to show in pop up.
Declare toPassArray in PopUpViewController i.e PopUpTableView here in below eg.

Obj C:

PopUpTableView *popupTableVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"PopUpTableView"];
popupTableVC.toPassArray = arrayToPass;

    STPopupController *popupController = [[STPopupController alloc] initWithRootViewController: popupTableVC];

[popupController presentInViewController:self];

Swift:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let popupTableVC: PopUpTableView = storyboard.instantiateViewController(withIdentifier: "PopUpTableView") as! PopUpTableView
popupTableVC.toPassArray = arrayToPass
let popup = STPopupController(rootViewController: popupTableVC)
popup.present(in: self, completion: nil)

And for passing data back on selecting table in popup, you can use either delegate or NSNotification on dismissing popup view..

Thanks

I have just figured it out myself. I haven't even tried it yet and I got your answer by mail.
Thank you very much.