Removing subview hierarchy from root view
In the root view controller I add a subview:
d4sViewController = [[D4sViewController alloc] initWithNibName:@"D4sViewCont开发者_StackOverflow社区roller" bundle:nil];
//----------------------------------------------------------------------
// Move your sub-view off the screen.
//----------------------------------------------------------------------
[self.view addSubview:d4sViewController.view];
CGRect rect = d4sViewController.view.frame;
CGPoint origin = CGPointMake(320, 0);
rect.origin = origin;
d4sViewController.view.frame = rect;
//----------------------------------------------------------------------
// Use a transform to slide it on.
//----------------------------------------------------------------------
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
d4sViewController.view.transform = CGAffineTransformMakeTranslation(-320, 0);
[UIView commitAnimations];
IN D4sViewController
I add 2 subviews:
d4sMainList1ViewController = [[D4sMainList1ViewController alloc] initWithNibName:@"D4sMainList1ViewController" bundle:nil];
// Move your sub-view off the screen.
//----------------------------------------------------------------------
[self.view addSubview:d4sMainList1ViewController.view];
From this subview, d4sMainList1ViewController
, I want to give a logout functionality and go back to root view controller by removing all subview.
-(IBAction)buttonLogoutClicked:(id)sender
{
//logout code i need to implement
}
Rootview => d4sViewController => d4sMainList1ViewController
(from here i need to remove all subviews of root and go back to displaying just the root view.)
To remove any subview have the send the subview the removeFromSuperView
message. See the UIView docs for details.
However, it looks like your stacking views when you don't need to. On a mobile screen a big pile of views is unusable. Look into using UINavigationController to managed a hierarchy of views/viewControllers for you.
精彩评论