diff --git a/CLFContainerViewController/CLFStackContainerViewController.h b/CLFContainerViewController/CLFStackContainerViewController.h index ec6be56..71e5ca2 100644 --- a/CLFContainerViewController/CLFStackContainerViewController.h +++ b/CLFContainerViewController/CLFStackContainerViewController.h @@ -57,6 +57,10 @@ typedef NS_ENUM(NSUInteger, CLFStackContainerPushPopDirections) { @property (readonly, nonatomic) UIViewController *rootViewController; @property (readonly, nonatomic) UIViewController *topViewController; +// This overrides readonly property in base class and make possible to replace view controllers hierarchies dynamically +// (similiar to UINavigationController) +@property (readwrite, nonatomic) NSArray *viewControllers; + // The default implementation uses this property to determine which // animations to use for the pushes and pops. // diff --git a/CLFContainerViewController/CLFStackContainerViewController.m b/CLFContainerViewController/CLFStackContainerViewController.m index 59ef4f3..a0d3bd3 100644 --- a/CLFContainerViewController/CLFStackContainerViewController.m +++ b/CLFContainerViewController/CLFStackContainerViewController.m @@ -68,6 +68,27 @@ - (UIViewController *)topViewController } +- (void)setViewControllers:(NSArray *)controllers +{ + NSAssert([controllers count] > 0, @"CLFStackContainerViewController should has at least one controller!"); + + NSArray *controllersToRemove = [self.viewControllers copy]; + + for (UIViewController *controller in controllers) + [super addViewController:controller]; + + [super switchToViewController:[controllers lastObject] + animated:NO + preAnimationSetup:NULL + animations:nil + animationDurations:nil + animationOptions:nil + completionBlock:^(BOOL finished) { + for (UIViewController *controller in controllersToRemove) + [super removeViewController:controller]; + }]; +} + - (void (^)())transitionUpPreAnimationBlock { return ^{