1

I'm currently designing a small application in which I have: - 1 menu (graphic buttons) - 1 content (basically a view) to display as a popover for each buttons

The user touch an UIButton, a content designed with Interface Builder (and driven by its own view controller) is shown into an UIPopoverController. The user switches some UISwitch, slides some UISliders, then dismiss the UIPopoverController by clicking outside (or on the close UIButton of the content of the considered UIPopoverController)

If the user touches the same button, of course, the UIPopoverController appears, with the previous values freshly modified

Question 1: Where to store data (at runtime I mean) ? Because, each nicely prepared content UI has its own view controller, the more natural way could be to put them there. BUT dismissing the UIPopoverController dismisses data too...

Question 2: How can I have my UIPopoverController pulling the freshest data (from the previous user or logic changes) ?

Any leads about best practices would be appreciated

gluon
  • 662
  • 1
  • 10
  • 18
  • One possible answer with code: http://stackoverflow.com/questions/10430734/how-to-display-a-view-made-with-interface-builder-as-a-uipopovercontroller – gluon May 07 '12 at 07:26

1 Answers1

1

What it sounds like you should do is have the main view controller that is responsible for showing the popovers store the data. Some things that should help:

  • In your main view controller, implement the UIPopoverControllerDelegate Protocol and have it be the delegate of the popover.
  • Implement some properties on the view controllers that allow you to get and set the values for them (the state of the switches, the values of the sliders, etc.)
  • When the popover controller is about to dismiss (implement the - (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController delegate method), grab the data you want to save from the navigation controller inside the popover.
  • Before a popover is shown, set all the properties on the view controller, that way it will have the most recent data.
Simon Goldeen
  • 9,080
  • 3
  • 36
  • 45
  • Hi Simon and thanks a lot for your (so fast) answer. I'm almost okay with the pattern, except the protocol part. I'm going to dig that especially. Ok to store (temporarily) data into the different view controllers. But what is the benefit of the protocol ? I mean, in any cases, I have to grab the data from the content of the popover to the main view controller, and I have to set all properties to the view controllers (probably inside willAppear I guess) ... I totally trust you about this pattern but it is only to be sure to understand well :) – gluon Apr 30 '12 at 20:06
  • @gluon the benefit of the delegate protocol is that if you set the `delegate` property of the `UIPopoverController` to `self` (or any object that implements the protocol) it will then get sent any delegate messages that it implements. In the case of `UIPopoverController`, you will get sent a message right before the popover dismisses and right after it has dismissed. If you want to do things in response to either of those events (such as grabbing data out of the presented view controller), that is the place to do so. – Simon Goldeen Apr 30 '12 at 20:10
  • Got it. Now moving to implement the display of all my views as popover :) Maxi Thanks. – gluon Apr 30 '12 at 20:18
  • (no success to implement it in my project, unfortunately. not because it isn't the solution, but because me...) – gluon Apr 30 '12 at 21:28