这个方法取值为空未做兼容,导致闪退
- (UIViewController*)getVCWithIndex:(NSInteger)index{
if (index < 0|| index >= self.param.wControllers.count) {
return nil;
}
if ([[self findBelongViewControllerForView:self].cache objectForKey:@(index)]) {
return [[self findBelongViewControllerForView:self].cache objectForKey:@(index)];
}
return self.param.wControllers[index];
}
UIViewController *newVC = [self getVCWithIndex:index];
[newVC beginAppearanceTransition:YES animated:YES];
[self addChildVC:index VC:newVC];
- (void)addChildVC:(NSInteger)index VC:(UIViewController*)newVC{
if (![[self findBelongViewControllerForView:self].childViewControllers containsObject:newVC]) {
[[self findBelongViewControllerForView:self] addChildViewController:newVC];
CGRect frame = CGRectMake(index * self.dataView.frame.size.width,0,self.dataView.frame.size.width,
self.dataView.frame.size.height);
newVC.view.frame = frame;
[self.dataView addSubview:newVC.view];
[newVC didMoveToParentViewController:[self findBelongViewControllerForView:self]];
[[self findBelongViewControllerForView:self].cache setObject:newVC forKey:@(index)];
}
}