Skip to content

Instantly share code, notes, and snippets.

@pita5
Created June 11, 2013 18:36
Show Gist options
  • Save pita5/5759479 to your computer and use it in GitHub Desktop.
Save pita5/5759479 to your computer and use it in GitHub Desktop.
//
// FRCTheParentViewController.m
// VCDemo
//
// Created by Matthew Wilkinson on 11/06/2013.
// Copyright (c) 2013 FreshCocoa. All rights reserved.
//
#import "FRCTheParentViewController.h"
@protocol FRCFirstChildProtocol <NSObject>
- (void)didTapClose;
@end
@interface FRCTheFirstChildViewController : UIViewController
@property (nonatomic, weak) id<FRCFirstChildProtocol> delegate;
@end
@implementation FRCTheFirstChildViewController
@end
@interface FRCTheSecondChildViewController : UIViewController
@end
@implementation FRCTheSecondChildViewController
@end
@interface FRCTheParentViewController () <FRCFirstChildProtocol>
@property (nonatomic) UIView* contentView;
@property (nonatomic) FRCTheFirstChildViewController* firstVC;
@property (nonatomic) FRCTheSecondChildViewController* secondVC;
@end
@implementation FRCTheParentViewController
- (void)didTapClose
{
[self.firstVC.view removeFromSuperview];
[self.firstVC didMoveToParentViewController:nil];
[self.contentView addSubview:self.secondVC.view];
[self.secondVC didMoveToParentViewController:self];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.contentView = [[UIView alloc] initWithFrame:self.view.bounds];
[self.contentView addSubview:self.contentView];
FRCTheFirstChildViewController* first = [[FRCTheFirstChildViewController alloc] init];
self.firstVC = first;
first.delegate = self;
[self addChildViewController:first];
FRCTheSecondChildViewController* second = [[FRCTheSecondChildViewController alloc] init];
self.secondVC = second;
[self addChildViewController:second];
[self.contentView addSubview:first.view];
[first didMoveToParentViewController:self];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment