1. How to create a controller
1.1. There are several common ways to create a controller:
1.1.1: Created by storyboard
1.1.2: directly create *viewcontroller = [[Yhviewcontroller alloc] init]; //1.1.3: Specify the Xib file to create *viewcontroller= [[Yhviewcontroller alloc] Initwithnibname:@ "yhviewcontroller" Bundle:nil];
2. Create a controller from storyboard
2.1: load Storyboard file First (Teststoryboard is storyboard filename)uistoryboard *storyboard = [Uistoryboard Storyboardwithname:@ "TestStoryboard" Bundle:nil]; //2.2: then initialize the controller in the storyboard
//2.2.1: Initialize the "initial controller" (the controller that the Arrow refers to) Yhviewcontroller *viewcontroller = [Storyboard Instantiateinitialviewcontroller]; //2.2.2: initialize the corresponding controller with an identity Yhviewcontroller *viewcontroller = [Storyboard instantiateviewcontrollerwithidentifier:@ "YH"];
3: Delay Loading of Controller view
3.1: The controller's view is delayed loading: reload when used
3.2: You can use the Isviewloaded method to determine whether a Uiviewcontroller view has been loaded
3.3: The controller's view is loaded and the Viewdidload method is called
4: Multi-controller
4.1: An iOS app rarely consists of a single controller, unless the app is incredibly simple
4.2: We need to manage these controllers when there are multiple controllers in the app
4.3: When there are multiple view, you can use a large view to manage 1 or more small view
4.4: Controller is the same, with 1 controllers to manage the other multiple controllers
4.5: For example, use a controller A to manage 3 controllers B, C, D
4.5.1: Controller A is referred to as the "parent controller" of Controller B, C, D
4.5.2: Controller B, C, D is referred to as controller A "sub-controller"
4.6: iOS provides 2 more special controllers for easy management of the controller
4.6.1:uinavigationcontroller: Easy to manage multiple controllers, easily switch between controllers, typical example is the system's own "settings" Application
4.6.2:uitabbarcontroller
Simple use of 5:uinavigationcontroller
5.1:uinavigationcontroller Steps to use
5.1.1: Initialize Uinavigationcontroller
5.1.2: Set UIWindow rootviewcontroller to Uinavigationcontroller
5.1.3: Depending on the situation, add the corresponding number of sub-controllers by the push method
5.2:uinavigationcontroller Sub-controller
//5.2.1:Uinavigationcontroller to save the sub-controller in the form of a stack@property (nonatomic,copy) Nsarray *viewcontrollers, @property (nonatomic,ReadOnly) Nsarray *childviewcontrollers;//5.2.2:use the push method to push a controller into the stack- (void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;//5.2.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;
6: How to modify the contents of the navigation bar
//6.1:the contents of the navigation bar are determined by the Navigationitem property of the stack top controller//6.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;//The view in the upper right corner@property (Nonatomic,retain) Uibarbuttonitem *rightbarbuttonitem;
OBJECTIVE-C Study notes: Management of Controllers