• This repository has been archived on 27/Jul/2020
  • Stars
    star
    111
  • Rank 314,510 (Top 7 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Custom view controller container for swiching sub view controller with a segmented control

FHSegmentedViewController

1 2 3

Requirements

  • iOS 6.1+
  • ARC

Installation

From CocoaPods

pod 'FHSegmentedViewController'

From source

  • Drag the FHSegmentedViewController folder to your project

Getting Started

  1. Create a subclass of FHSegmentedViewController in your project
#import "FHSegmentedViewController.h"

@interface MasterViewController : FHSegmentedViewController

2.Implement - (void)viewDidLoad

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self setViewControllers:@[[self.storyboard instantiateViewControllerWithIdentifier:@"firstSubViewController"], [self.storyboard instantiateViewControllerWithIdentifier:@"secondSubViewController"]]];
}
  1. Push an instance of AnotherViewController.
    UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"firstSubViewController"];
    [self pushViewController:viewController title:@"anotherViewController"];

Note: If the view controller you want to present is a UITableViewController you have to override didMoveToParentViewController:in it with this:

    - (void)didMoveToParentViewController:(UIViewController *)parent
    {
        if (parent) {
            CGFloat top = parent.topLayoutGuide.length;
            CGFloat bottom = parent.bottomLayoutGuide.length;

            if (self.tableView.contentInset.top != top) {
                UIEdgeInsets newInsets = UIEdgeInsetsMake(top, 0, bottom, 0);
                self.tableView.contentInset = newInsets;
                self.tableView.scrollIndicatorInsets = newInsets;
            }
        }

        [super didMoveToParentViewController:parent];
    }