Trevor
Trevor

Reputation: 4860

Programmatically Re-Load UIViewController for "Start Over" Button

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?

Upvotes: 1

Views: 806

Answers (2)

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31730

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;
}

Upvotes: 2

mackworth
mackworth

Reputation: 5953

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.

Upvotes: 0

Related Questions