Master • 1. Multiple methods for creating controllers and views • 2. simple use of uinavigationcontroller: Add/Remove sub-controllers • 3. uinavigationbar content settings • 4. segue Data Transfer • 1. Multiple methods for creating controllers and views
Question 1: How to Create a controller?
• Common methods for creating controllers are as follows: 1. Create controllers using storyboard • load the storyboard file first (test is the name of the storyboard file)
Uistoryboard * storyboard = [uistoryboard storyboardwithname: @ "test" Bundle: Nil];
• Initialize the controller in the storyboard. initialize the "initial controller" (Controller indicated by the arrow)
Whbviewcontroller * Vc = [storyboard instantiateinitialviewcontroller];
Initialize the corresponding controller through an identifier
Whbviewcontroller * Vc = [storyboard instantiateviewcontrollerwithidentifier: @ "VC"];
2 directly create
Whbviewcontroller * Vc = [[whbviewcontroller alloc] init];
3. Specify the XIB file to create
Whbviewcontroller * Vc = [[whbviewcontroller alloc] initwithnibname: @ "whbviewcontroller" Bundle: Nil];
Question 2: What are the priorities of view creation modes?
PS: delayed loading of the controller View
• The Controller's view is delayed loading: loaded when used • you can use the isviewloaded method to determine whether the view of a uiviewcontroller has been loaded • after the Controller's view is loaded, the viewdidload method is called.
@ Interface uiview: uiresponder <nscoding, uiappearance, uiappearancecontainer, uidynamicitem>/*** initialize a UI control using a frame */-(ID) initwithframe :( cgrect) frame; // yes: interaction with the user @ property (nonatomic, Getter = isuserinteractionenabled) bool userinteractionenabled; // default is yes // a tag of the control (the parent control can find the corresponding child control through the tag) @ property (nonatomic) nsinteger tag; // default is 0 // layer (can be used to set the rounded corner effect \ shadow effect) @ property (nonatomic, readonly, Retain) calayer * layer; @ end @ interface uiview (uiviewgeometry) // position and size (take the upper left corner of the parent control as the coordinate origin (0, 0) @ property (nonatomic) cgrect frame; // position and size (using the upper left corner as the coordinate origin (0, 0) @ property (nonatomic) cgrect bounds; // midpoint (with the upper left corner of the parent control as the coordinate origin (0, 0) @ property (nonatomic) cgpoint center; // deformation attribute (Pan, zoom, or rotate) @ property (nonatomic) cgaffinetransform transform; // default is cgaffinetransformidentity // yes: supports multi-point touch @ property (nonatomic, Getter = ismu) Ltipletouchenabled) bool multipletouchenabled; // default is no @ end @ interface uiview (uiviewhierarchy) // parent control @ property (nonatomic, readonly) uiview * superview; // subcontrol (the newly added control is all behind the subviews array by default, and the newly added control is displayed at the top \ top) @ property (nonatomic, readonly, copy) nsarray * subviews; // obtain the window @ property (nonatomic, readonly) uiwindow * window of the current control; // remove a control from the parent control-(void) removefromsuperview; // Add a child control (you can insert the child control into the subviews array in Dex location)-(void) insertsubview :( uiview *) view atindex :( nsinteger) index; // switch the location of the Child control stored in the subviews array-(void) exchangesubviewatindex :( nsinteger) index1 withsubviewatindex :( nsinteger) index2; // Add a child control (the newly added controls are all behind the subviews array by default, and the newly added controls are displayed on the top \ top by default) -(void) addsubview :( uiview *) view; // Add a sub-control view (blocked under siblingsubview)-(void) insertsubview :( uiview *) view belowsubview :( uiview *) siblingsubview; // Add a subcontrol View Iblingsubview above)-(void) insertsubview :( uiview *) view abovesubview :( uiview *) siblingsubview; // pull a subcontrol to the top (top) to display-(void) bringsubviewtofront :( uiview *) view; // pull a subcontrol to the bottom (bottom) to display-(void) sendsubviewtoback :( uiview *) view; /** automatically called by the system (left to the subclass for implementation) **/-(void) didaddsubview :( uiview *) subview;-(void) willremovesubview :( uiview *) subview; -(void) willmovetosuperview :( uiview *) newsuperview;-(void) didmovetosupervi EW;-(void) willmovetowindow :( uiwindow *) newwindow;-(void) didmovetowindow; /** automatically called by the system ** // is the view subcontrol or the subcontrol of the subcontrol (whether it is the descendant of the View)-(bool) isdescendantofview :( uiview *) view; // returns yes for self. // obtain the corresponding sub-control through tag (or the sub-control of the sub-Control)-(uiview *) viewwithtag :( nsinteger) Tag; // recursive search. includes self/** automatically called by the system (left to the subclass for implementation) ** // when the frame of the control changes, it will be called, generally, the position and size of the layout sub-control are overwritten here. // After rewriting this write method, you must call [Super layoutsubviews];-(voi D) layoutsubviews; @ end @ interface uiview (uiviewrendering) // yes: content beyond the control's border is cut off @ property (nonatomic) bool clipstobounds; // background color @ property (nonatomic, copy) uicolor * backgroundcolor; // default is nil // transparency (0.0 ~ 1.0) @ property (nonatomic) cgfloat Alpha; // default is 1.0 // yes: Opaque No: transparent @ property (nonatomic, Getter = isopaque) bool opaque; // default is yes // yes: hide no: display @ property (nonatomic, Getter = ishidden) bool hidden; // content mode @ property (nonatomic) uiviewcontentmode contentmode; // default is expired @ end @ interface uiview (synchronized) + (void) animatewithduration :( nstimeinterval) duration delay :( nstimeinterval) delay options :( uiviewanimationoptions) Options animations :( void (^) (void) animations completion :( void (^) (bool finished) completion; + (void) animatewithduration :( nstimeinterval) Duration animations :( void (^) (void )) animations completion :( void (^) (bool finished) completion; + (void) animatewithduration :( nstimeinterval) Duration animations :( void (^) (void) animations; + (void) interval :( nstimeinterval) duration delay :( nstimeinterval) delay interval :( cgfloat) dampingratio initialspringvelocity :( cgfloat) velocity options :( uiviewanimationoptions) Options animations :( void (^) (void )) animations completion :( void (^) (bool finished) completion; @ end
Definition of uiview attributes • 2. simple use of uinavigationcontroller: Add/Remove sub-controllers • uinavigationcontroller use steps ø initialize uinavigationcontroller ø set the rootviewcontroller of uiwindow to uinavigationcontroller. ø depending on the actual situation, add the corresponding number of sub-controllers using the push method • uinavigationcontroller saves the sub-controllers in the form of stacks
@ Property (nonatomic, copy) nsarray * viewcontrollers;
@ Property (nonatomic, readonly) nsarray * childviewcontrollers;
• Use the push method to push a controller to the stack
-(Void) pushviewcontroller :( uiviewcontroller *) viewcontroller animated :( bool) animated;
• The pop method can be used to remove the Controller ø remove the Controller at the top of the stack
-(Uiviewcontroller *) popviewcontrolleranimated :( bool) animated;
Return to the specified sub-Controller
-(Nsarray *) poptoviewcontroller :( uiviewcontroller *) viewcontroller animated :( bool) animated;
Return to the root controller (stack bottom Controller)
-(Nsarray *) poptorootviewcontrolleranimated :( bool) animated;
• 3. uinavigationbar content settings • the content of the navigation bar is determined by the navigationitem attribute of the stack top controller. • The following attributes of uinavigationitem affect the content of the navigation bar.
@ Property (nonatomic, retain) uibarbuttonitem * backbarbuttonitem;
Ø middle title View
@ Property (nonatomic, retain) uiview * titleview;
Title text in the middle
@ Property (nonatomic, copy) nsstring * title;
Ø view in the upper left corner
@ Property (nonatomic, retain) uibarbuttonitem * leftbarbuttonitem;
Ø uibarbuttonitem * rightbarbuttonitem view in the upper-right corner
@ Property (nonatomic, retain) uibarbuttonitem * rightbarbuttonitem;
• 4. Data Transmission of segue
Question 1: What is segue?
• Each line on the storyboard for interface jump is a uistoryboardsegue object (segue for short)