There are three ways to create a controller in iOS:
1. Create with Storyboard
Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@ "Apply" bundle:nil]; Schemeviewcontroller *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
Return button @property (nonatomic,retain) Uibarbuttonitem *backbarbuttonitem;//Middle title View @property (Nonatomic,retain) in the upper-left corner UIView *titleview;//in the middle of the title text @property (nonatomic,copy) nsstring *title;//the upper left corner of the view @property (Nonatomic, Retain) Uibarbuttonitem *leftbarbuttonitem; Uibarbuttonitem *rightbarbuttonitem //upper-right corner of the View @property (Nonatomic,retain) Uibarbuttonitem *rightbarbuttonitem;
iOS Development: Multi-controller Management in iOS