1

I have a UITableViewController. When you select a cell, it calls init on a UIViewController, which programmatically creates a bunch of views and adds them to the screen. Everything here works fine.

As the user interacts with the app, the views are moved or deleted. I want to have a button where the user can "Start Over" and the UIViewController will init and draw itself like new on the screen. Basically I want the same behavior as if the user went "back" to the UITableViewController and clicked on that same item again.

I can create the button and wire it up and everything. What I need to know is how to release and re-initialize the UIViewController.

How do I do that?

Trevor
  • 4,620
  • 2
  • 28
  • 37

2 Answers2

2

Create your UIViews in UIMyViewController controller. and use the below code for pushing your view controller in navigation stack.

-(void) buttonClcked:(id) sender
{
    //Create for pushing another view controller in navigation stack.
    UIMyViewController *myViewController = [[UIMyViewController alloc] init];
    //to push view controller in navigation stack.
    [self.navigationController pushViewController:myViewController animated:YES];

    // you could release it because now it's retained by your UINavigationController

    [myViewController release];
     myViewController = nil;
}
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
  • You hit it close and your answer led me to the right one, which is here: [Pop and Replace a View](http://stackoverflow.com/questions/410471/how-can-i-pop-a-view-from-a-uinavigationcontroller-and-replace-it-with-another-in). – Trevor Jun 11 '11 at 05:48
0

Well, seems to me, you have two choices:

  1. You can exit the UITableViewController (via a delegate call to the parent) and have it destroy it and relaunch it. (or)
  2. You can put your view building code into a separate routine (not a NIB or loadView or ViewDidLoad or even ViewDidAppear, and then release all the subViews of self.view and call the view builder again.
mackworth
  • 5,873
  • 2
  • 29
  • 49