多标签切换界面解耦,分散代码,避免一个类中代码成千上万行
思路简单,效果很好
思路:当前控制器添加其他控制器为子控制器,根据标签切换显示子控制器的View,关键是新建一个UIView做容器
OneViewController *viewController1 = [[OneViewController alloc] init];
[self addChildViewController:viewController1];
TwoViewController *viewController2 = [[TwoViewController alloc] init];
[self addChildViewController:viewController2];
ThreeViewController *viewController3 = [[ThreeViewController alloc] init];
[self addChildViewController:viewController3];
FourViewController *viewController4 = [[FourViewController alloc] init];
[self addChildViewController:viewController4];
FiveViewController *viewController5 = [[FiveViewController alloc] init];
[self addChildViewController:viewController5];
- (void)goChangeViewWithIndex:(NSInteger)index{
UIView * view = [[self.childViewControllers firstObject]view];
if ([self.typeCar isEqualToString:@"0"]) {
view = [self.childViewControllers[index] view];
}else{
switch (index) {
case 0:
{
view = [self.childViewControllers[3] view];
}
break;
case 1:
{
view = [self.childViewControllers[4] view];
}
break;
default:
break;
}
}
[self.containView addSubview:view];
[self.containView bringSubviewToFront:view];
}
image
[图片上传中...(image-56e933-1510043511141-3)]
image image image
网友评论