Here is the situation:
I have a Master-Detail setup for my app. In the MasterViewController I have a button called "Filter".
Through the storyboard I set up a popover view that appears once the Filter button is pressed. There is no IBAction on the filter button, or any programmatic way that calls the popover.
In my FilterViewController class I have all the UI elements that populate the popover view, with which the user can interact and select all sorts of stuff.
At the top of the popover view there is an "Update" button.
I want to record the user's decisions, and pass them back to the MasterViewController once "Update" is pressed.
Here is the code:
MasterViewController.swift
class MasterViewController: UITableViewController{
override func awakeFromNib() {
super.awakeFromNib()
self.clearsSelectionOnViewWillAppear = false
self.preferredContentSize = CGSize(width: 320.0, height: 600.0)
}
override func viewDidLoad() {
super.viewDidLoad()
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//more standard MasterView code...
}
FilterViewController.swift
class FilterViewController: UIViewController{
var someUIStuff:String?
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
scrollView = self.view as UIScrollView
scrollView.contentSize = CGSizeMake(300, 600)
}
//presumably, this is from where I should pass the variables to the MasterView
@IBAction func updateBtnPressed(sender: AnyObject) {
//this actually gets set by user in the popover view; I have no problem recording it, but I want to pass *someUIStuff* back to MasterView
someUIStuff = "Hello, MasterView"
}
//other code that populates the popover with UI stuff
relevant part of storyboard:
The arrow between the two views is a Popover presentation segue to Filter View Controller
I have tried following the instructions here:
SWIFT: No idea how to get back the selected value from a popover to the calling controller
Swift, Pass data back from popover to view controller
To no avail; both seem to use some programmatic access to the popover view which I do not have.
Any help is greatly appreciated!
Best,
Jona
If you want to pass data from one view to another you can simply set NSUserDefaults and read it wherever you need.
Think you have variable call Name in view No.01, You can store Name in NSUserdefault object by giving it a unique key(id). In this case its "name"
Then think you want to access it in any other view so use the key you assigned and get the value into a variable like this
Using this you can pass data through view controllers.
Example, Think this is your popup view
Now you have set Name and Age from your pop up view to NSUserdefaults so now you have to get them into your master view
In your viewDidLoad() method in masterview
Now you have the date in two variables so you can use them anywhere.