There are three ways to create a controller in iOS:
1. Create with Storyboard
Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@ "Apply"*SCHEMEVC = [Storyboard Instantiateviewcontrollerwithidentifier:@ "schemeviewcontroller"];
2. Specify the Xib file to create
Yfviewcontroller *MJ = [[Yfviewcontroller alloc] Initwithnibname:@ "yfviewcontroller" Bundle:nil];
3. Create directly
Yfviewcontroller *MJ = [[Yfviewcontroller alloc] init];
An iOS app rarely consists of a single controller, unless the app is extremely simple, and when there are multiple controllers in the app, we need to manage these controllers, there are multiple view, you can use a large view to manage 1 or more small view, the controller is the same With 1 controllers to manage the other multiple controllers, for example, with a controller A to manage 3 controllers B, C, D, controller A is called Controller B, C, D "Parent Controller", Controller B, C, D is called controller A "sub-controller", in order to facilitate the management of the controller, iOS offers 2 more special controllers, Uinavigationcontroller and Uitabbarcontroller. Uinavigationcontroller Saving a sub-controller as a stack • Use the push method to push a controller into the stack
-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
• 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 sub-controller -(Nsarray *) Poptoviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated; // Back to root controller (stack bottom controller)-(Nsarray *) poptorootviewcontrolleranimated: (BOOL) animated;
• The contents of the navigation bar are determined by the Navigationitem property of the top controller, Uinavigationitem has the following properties affecting 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; // the middle title text @property (nonatomic,copy) nsstring *title; // the view in the upper-left corner @property (nonatomic,retain) uibarbuttonitem * *rightbarbuttonitem // the upper right corner of the view @property (nonatomic,retain) Uibarbuttonitem *rightbarbuttonitem;
View loading process in controller: The method called by the controller's view load during the entire life cycle: memory warning Processing:
iOS Development: Multi-controller Management in iOS