两个viewController的view显示到另一个viewController
程序员文章站
2024-01-14 22:33:52
...
就是addChildViewController,没什么好解释的,代码粘过来方便下次偷懒
#import "SegmentHistoryViewController.h"
#import "HistoryViewController.h"
#import "PatientHistoryViewController.h"
@interface SegmentHistoryViewController ()
{
HistoryViewController *historyVC;
PatientHistoryViewController *patientHisVC;
UIView *leftView, *rightView;
}
@end
@implementation SegmentHistoryViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *segArr = @[@"接诊统计", @"接诊记录"];
UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:segArr];
segment.frame = CGRectMake(10, 100, self.view.frame.size.width-2*87, 25);
segment.selectedSegmentIndex = 0;
segment.tintColor = [UIColor whiteColor];
[segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segment;
historyVC = [HistoryViewController new];
patientHisVC = [PatientHistoryViewController new];
[self addChildViewController:historyVC];
[self addChildViewController:patientHisVC];
//将viewController的view定制frame之后加入到self.view上。
historyVC.view.frame = self.view.bounds;
patientHisVC.view.frame = self.view.bounds;
patientHisVC.view.hidden = YES;
[self.view addSubview:historyVC.view];
[self.view addSubview:patientHisVC.view];
}
- (void)segmentAction:(UISegmentedControl *)sender {
if (sender.selectedSegmentIndex == 0) {
//接诊统计
historyVC.view.hidden = NO;
patientHisVC.view.hidden = YES;
[self.view resignFirst];
} else {
//就诊记录
historyVC.view.hidden = YES;
patientHisVC.view.hidden = NO;
}
}
@end
上一篇: swift deinit 不被执行
下一篇: oc调js方法