First, Master
(1) Multiple ways to create a controller and view
(2) Simple use of Uinavigationcontroller: Add \ Remove Sub-controller
(3) Setting of Uinavigationbar content
(4) Life cycle method of the Controller
Second, the creation of the controller
(1) There are several common ways to create controllers:
1) Create with storyboard
2) Create directly
Mjviewcontroller *MJ = [[Mjviewcontroller alloc] init];
3) Specify the Xib file to create
Mjviewcontroller *MJ = [[Mjviewcontroller alloc] initwithnibname:@ "Mjviewcontroller" bundle:nil];
(2) Load the storyboard file first (test is the file name of storyboard)
Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@ "Test" bundle:nil];
(3) Then initialize the controller in the storyboard
1) Initialize "Initial controller" (the controller that the Arrow refers to)
Mjviewcontroller *MJ = [Storyboard Instantiateinitialviewcontroller];
2) initialize the corresponding controller with an identity
Mjviewcontroller *MJ = [Storyboard instantiateviewcontrollerwithidentifier:@ "MJ"];
Third, the Controller view
(1) Creation of Mjviewcontroller view
(2) Delay loading of Controller view
1) The view of the controller is delayed loading: reload when used
2) You can use the Isviewloaded method to determine whether a Uiviewcontroller view has been loaded
3) The view of the controller is loaded and the Viewdidload method is called
Four, multi-controller management
(1) Multi-controller
1) An iOS app rarely consists of a single controller, unless the app is extremely simple
2) We need to manage these controllers when there are multiple controllers in the app
3) When you have multiple view, you can use a large view to manage 1 or more small view
4) controller is the same, with 1 controllers to manage the other multiple controllers
5) For example, use a controller A to manage 3 controllers B, C, D
Controller A is referred to as the "parent controller" of Controller B, C, D
Controller B, C, d are referred to as controller A's "sub-controller"
6) for easy management of the controller, iOS provides 2 more special controllers
Uinavigationcontroller
Uitabbarcontroller
Wu, Uinavigationcontroller
(1) with Uinavigationcontroller, it is easy to manage multiple controllers and easily switch between controllers, the typical example being the "settings" application that comes with the system
(2) Simple use of Uinavigationcontroller
1) Steps to use Uinavigationcontroller
Initialize Uinavigationcontroller
Set the Rootviewcontroller for UIWindow to Uinavigationcontroller
Depending on the situation, add the corresponding number of sub-controllers by the push method
(3) Uinavigationcontroller Sub-controller
1) Uinavigationcontroller Save the sub-controller in the form of a stack
@property (nonatomic,copy) Nsarray *viewcontrollers;
@property (nonatomic,readonly) Nsarray *childviewcontrollers;
2) Use the push method to push a controller into the stack
-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
3) Use the Pop method to remove the controller
Remove the controller from the top of the stack
-(Uiviewcontroller *) popviewcontrolleranimated: (BOOL) animated;
Back to the specified child controller
-(Nsarray *) Poptoviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
Back to root controller (stack bottom controller)
-(Nsarray *) poptorootviewcontrolleranimated: (BOOL) animated;
(4) Uinavigationcontroller Sub-controller
1) Uinavigationcontroller Save the sub-controller in the form of a stack
@property (nonatomic,copy) Nsarray *viewcontrollers;
@property (nonatomic,readonly) Nsarray *childviewcontrollers;
2) Use the push method to push a controller into the stack
-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
3) Use the Pop method to remove the controller
Remove the controller from the top of the stack
-(Uiviewcontroller *) popviewcontrolleranimated: (BOOL) animated;
Back to the specified child controller
-(Nsarray *) Poptoviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
Back to root controller (stack bottom controller)
-(Nsarray *) poptorootviewcontrolleranimated: (BOOL) animated;
(5) View structure of Uinavigationcontroller
(6) How to modify the contents of the navigation bar
1) The contents of the navigation bar are determined by the Navigationitem property of the stack top controller
2) Uinavigationitem has the following properties that affect the contents of the navigation bar
The Back button in the upper-left corner
@property (Nonatomic,retain) Uibarbuttonitem *backbarbuttonitem;
The middle title view
@property (Nonatomic,retain) UIView *titleview;
Middle Caption text
@property (nonatomic,copy) NSString *title;
The view in the upper-left corner
@property (Nonatomic,retain) Uibarbuttonitem *leftbarbuttonitem;
Uibarbuttonitem *rightbarbuttonitem view in the upper right corner
@property (Nonatomic,retain) Uibarbuttonitem *rightbarbuttonitem;
ios--Summary series eight controller management