0

I have two UIViewControllers. In first UIViewController I have a UITableView as a subview. When any one of the UITableViewCell is selected, a UIView(as a subview) will be displayed, which have 9 buttons. When any one of the button is pressed, Second UIViewController will be presented. When user press custom back button on second UIViewController, First UIViewController have to be presented with all previous selected UITableViewCell and corresponding subviews open. How to achieve this. Is there any process to save UIViewController's state at a desired time.

Any suggestion will be greatly appreciated.

NANNAV
  • 4,875
  • 4
  • 32
  • 50
Ramu Pasupuleti
  • 888
  • 2
  • 15
  • 35

1 Answers1

0

If your are using a Navigation controller, navigating from one controller to another, your parent view controller will not be deallocated. Hence you can maintain state of that first view controller by means of properties or something else. When viewWillAppear is called for that controller, you can make use of that and update the controller accordingly.

Adithya
  • 4,545
  • 3
  • 25
  • 28
  • I am not using navigation controller. Is there any way to save the state. I am using two individual UIViewControllers – Ramu Pasupuleti Jun 10 '13 at 06:57
  • Can you provide some sample code or link to preserve state. Now I have embed Navigation Controller to second UIViewcontroller – Ramu Pasupuleti Jun 10 '13 at 07:00
  • Your first view controller should be the root view controller of a navigation controller. Then you can just push the second view controller through the navigation controller. Refer http://www.icodeblog.com/2011/10/11/back-to-basics-an-introduction-to-view-controllers/ – Adithya Jun 10 '13 at 07:06
  • Maintaining the states is nothing complicated like it sounds. In a simple eg, you had mentioned when a cell is selected, a view will be displayed. So in the controller you maintain a BOOL variable say shouldShowView. If the view was being shown when you had navigate to the second view controller, on return to the first view controller in the viewWillAppear you check for the shouldShowView value and hide/unhide the view accordingly. – Adithya Jun 10 '13 at 07:10
  • @Hi Adithya, Thanks for the link. I will try it get back to you. I have signin uiviewcontroller as a root view controller. After signin only these above two uiviewcotrollers will come. – Ramu Pasupuleti Jun 10 '13 at 07:12