UINavigationController navigation controller and ledcontroller
I. Navigation View Controller
1. Manage view Controllers
2. control navigation between view Controllers
3. Manage view controllers in the form of pressure stacks and outbound stacks
4. You must set the Root View Controller for the navigation View Controller.
5. navigation is the view controller that contains UINavigationBar, And the UINAvigationBar is managed by each View Controller.
UINavigationBar contains NavigationItem (one title and two buttons)
6. The push stack is displayed by alloc new objects, and the POP stack is returned by existing objects, so do not use alloc
// Initialize the Root View
FirstViewController * firstViewController = [[FirstViewController alloc] init];
// Create a navigation View Controller and set its Root View Controller
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController: firstViewController];
// If you use the navigation View Controller to manage the view, do not use firstViewController as the Root View of the window and use navigation view control. Because the navigation View Controller has taken over the view
Self. window. rootViewController = navigationController;
// Because of the lazy loading mechanism of UIViewController, you must use its view to call a series of view creation and display processes.
// Trying to create a controller is equivalent to creating an object in the memory.
SecondViewController * secondViewController = [[SecondViewController alloc] init];
// Hide the navigation bar
NavigationController. navigationBar. hidden = YES;
// Put secondViewController into the navigation View Controller in the form of a pressure Stack
[Self. navigationController pushViewController: secondViewController animated: YES];
// Pop the current object to the previous view
[Self. navigationController popViewControllerAnimated: YES];
// Pop to the root Attempt
[Self. navigationController popToRootViewControllerAnimated: YES];
// View Controller specified by pop
NSArray * array = self. navigationController. viewControllers;
[Self. navigationController popToViewController: [array objectAtIndex: 0] animated: YES];
The information of only elements in the output array (memory address and type)
NSLog (@ "% @", [array objectAtIndex: 0]);
Number of elements in the output Array
NSLog (@ "----- >>>>> ~~~ % D ", [array count]);
Ii. UIBarButtonItem
// Create a UIBarButtonItem
UIBarButtonItem * rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle :@"
Set title
"Style: UIBarButtonItemStylePlain (set type) target: self (set target) action: @ selector (btnCilck :) (binding method)];
// Set the right button of the item
Self. navigationItem. rightBarButtonItem = rightBarButtonItem;
3. Pass the lifecycle Value
// Assign a value to the attribute value of the FirstViewController object
-(Void) viewWillDisappear :( BOOL) animated
{
UITextField * textFiled = (UITextField *) [self. view viewWithTag: 100];
// Obtain the current navigation attempt controller, such as all the attempt controller objects contained
NSArray * array = self. navigationController. viewControllers;
// Obtain the root attempt object
FirstViewController * fv = [array objectAtIndex: 0];
// The content of the input box is assigned to the root attempt attribute.
Fv. value = textFiled. text;
NSLog (@ "region ~~~ ");
[Super viewWillDisappear: YES];
}
// Pass the value to the attribute value of the FirstViewController object
-(Void) viewWillAppear :( BOOL) animated
{
NSLog (@ "I have come back ~~ ");
UITextField * textFiled = (UITextField *) [self. view viewWithTag: 100];
TextFiled. text = self. value;
[Super viewWillAppear: YES];
}
Iv. Lifecycle
// LoadView and viewDidLoad are loaded only once in the lifecycle of an attempt controller.
// ViewWillAppear and viewDidAppear are executed only when the View display function is executed.
// The current attempt is loading
-(Void) loadView
{
NSLog (@ "current attempt to load ");
[Super loadView];
}
// The current attempt has been loaded
-(Void) viewDidLoad
{
[Super viewDidLoad];
NSLog (@ "current attempt to Load completed ");
}
// The current attempt to display
-(Void) viewWillAppear :( BOOL) animated
{
NSLog (@ "current attempt to display ");
[Super viewWillAppear: YES];
}
// The current attempt has been shown
-(Void) viewDidAppear :( BOOL) animated
{
NSLog (@ "the current attempt has been shown ");
[Super viewDidAppear: YES];
}
// The current attempt will disappear
-(Void) viewWillDisappear :( BOOL) animated
{
NSLog (@ "---- >>> current attempt to disappear ");
[Super viewWillDisappear: YES];
}
// The current attempt has disappeared
-(Void) viewDidDisappear :( BOOL) animated
{
NSLog (@ "---- >>> the current attempt has disappeared ");
[Super viewDidDisappear: YES];
}
// This method is automatically called when an attempt is made to control the release of the Host Object (manual Memory Management)
-(Void) dealloc
{
NSLog (@ "trying to release the controller ");
[Super dealloc];
}
//
Kill attempt Controller
[Remove the second view controller (last returned) release];