1 #import "RootViewController.h"2 #import "LoginViewController.h"3 #import "RegistViewController.h"4 #import "PasswardViewController.h"5 #import "RootView.h"6 7 @interfaceRootviewcontroller ()8@property (nonatomic, strong) Rootview *Rootview;9@property (nonatomic, strong) Loginviewcontroller *LOGINVC;Ten@property (nonatomic, strong) Registviewcontroller *REGISTVC; One@property (nonatomic, strong) Passwardviewcontroller *PASSWARDVC; A - @end - the @implementationRootviewcontroller - -- (void) Loadview { -Self.rootview =[[Rootview alloc] Initwithframe:[uiscreen mainscreen].bounds]; +Self.view =Self.rootview; - + } A at -- (void) Viewdidload { - [Super Viewdidload]; - - //initializing the View controller -SELF.LOGINVC =[[Loginviewcontroller alloc] init]; inSELF.REGISTVC =[[Registviewcontroller alloc] init]; -SELF.PASSWARDVC =[[Passwardviewcontroller alloc] init]; to + - //segment Adding an event the [self.rootView.segment addtarget:self Action: @selector (click:) forcontrolevents:uicontroleventvaluechanged]; * $ }Panax Notoginseng - the //Implement click Events +- (void) Click: (Uisegmentedcontrol *) Sender { A the Switch(sender.selectedsegmentindex) { + Case 0: - //Remove the topmost child view in the parent view $[[Self.rootView.subviews Objectatindex:0] Removefromsuperview]; $ - //Add a new view - [Self.rootview AddSubview:self.loginVC.view]; the - //Display the segment selector at the outermost layerWuyi [Self.rootview bringSubviewToFront:self.rootView.segment]; the Break; - Wu Case 1: - //Remove the topmost child view in the parent view About[[Self.rootView.subviews Objectatindex:0] Removefromsuperview]; $ - //Add a new view - [Self.rootview AddSubview:self.registVC.view]; - A //Display the segment selector at the outermost layer + [Self.rootview bringSubviewToFront:self.rootView.segment]; the Break; - $ Case 2: the //Remove the topmost child view in the parent view the[[Self.rootView.subviews Objectatindex:0] Removefromsuperview]; the the //Add a new view - [Self.rootview AddSubview:self.passwardVC.view]; in the //Display the segment selector at the outermost layer the [Self.rootview bringSubviewToFront:self.rootView.segment]; About Break; the the default: the Break; + } - } the @end
Add several controllers to the Uisegmentedcontrol