Small size elder brother Big God code, indeed streamlined!
1, the final results such as the following three diagram, click One,two,three, respectively, 3 different controllers appear
Direct code: (three controller created on it)
#import "ViewController.h"#import "ZWOneViewController.h"#import "ZWTwoViewController.h"#import "ZWThreeViewController.h"@interfaceViewcontroller ()/** The controller being displayed*/@property (Weak, nonatomic) Uiviewcontroller*SHOWINGVC;/** Controller Array*/@property (Strong, nonatomic) Nsarray*allvcs;//three properties in place of a controller@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Self.allvcs=@[[[Zwoneviewcontroller alloc] init], [[Zwtwoviewcontroller alloc] init], [[Zwthreeviewcontroller alloc] init];}-(Ibaction) ButtonClick: (UIButton *) button {//removing the currently displayed controller[Self.showingVC.view Removefromsuperview]; //get the position index of the controllerNsuinteger index =[Button.superview.subviews Indexofobject:button]; //Add Controller ViewSELF.SHOWINGVC =Self.allvcs[index]; //Set DimensionsSelf.showingVC.view.frame = CGRectMake (0, -, Self.view.frame.size.width, Self.view.frame.size.height- -); //adding to the controller[Self.view AddSubview:self.showingVC.view];}
Note: 1, extensibility is very good, directly in the array to add the controller need to add
2, because is the index, must pay attention to the order of three controllers, otherwise there will be a click after the other controller. Such as:
iOS development small function of 9:5 code to take care of simple parent-child controller