Giter VIP home page Giter VIP logo

ngsegmentedviewcontroller's Introduction

NGSegmentedViewController: A segmented view controller

Build Status

UIViewController subclass using SDSegmentedControl and View Controller Containment API's to switch between child view controllers

NGSegmentedViewController

(click to download a video of the controller in action).

Features

  • Uses View Controller Containment API's to display a list of view controllers
  • Uses the excellent SDSegmentedControl to display a view controller switcher at the top
  • Can be used with code and Interface Builder
  • Can be used with Autolayout
  • When using UITableView's or UICollectionView's automatically adjusts contentInset and scrollIndicatorInsets to accomodate for segmented control
  • Allows for a delegate to be notified when the selected view controller will / did change

Requirements

  • ARC
  • Xcode 4.4+ (needed for modern Objective-C syntax)
  • iOS 6+

Installation

From CocoaPods

Add pod 'NGSegmentedViewController' to your Podfile.

Manually

Important note if your project doesn't use ARC: you must add the -fobjc-arc compiler flag to NGSegmentedViewController.m in Target Settings > Build Phases > Compile Sources.

  • Drag the NGSegmentedViewController/NGSegmentedViewController folder into your project
  • Download SDSegmentedControl and drag SDSegmentedControl.{h,m} into your project
  • Add the QuartzCore framework to your project
  • You might need to change the #import <SDSegmentedControl/SDSegmentedControl.h> in NGSegmentedViewController.h to #import "SDSegmentedControl.h"

Demos

I have added two demos. NGSegmentedViewController example uses code to set up a segmented view controller and NGSegmentedViewController IB example uses Interface Builder to set one up.

Note

As this is my first open source iOS control, it is possible that I made mistakes. Furthermore, I only implemented features that seemed useful to me. If you find any errors or want extra features, feel free to fork this project and sent in a Pull Request.

Usage

Instantiate a segmented view controller with initWithViewControllers: or initWithViewControllers:titles:.

When using Interface Builder, create a subclass and overwrite awakeFromNib to call setupWithViewControllers: or setupWithViewControllers:titles:.

License and copyright

All source code is licensed under the MIT-License.

Copyright 2013 Nicky Gerritsen.

Authors

ngsegmentedviewcontroller's People

Contributors

lozhuf avatar nickygerritsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

lozhuf

ngsegmentedviewcontroller's Issues

setting selectedIndex before view appears will crash

ib example:

@implementation NGStoryBoardSegmentedViewViewController

  • (void)awakeFromNib {
    [super awakeFromNib];

    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    UIViewController *firstVC = [storyBoard instantiateViewControllerWithIdentifier:@"First"];
    UIViewController *tableVC = [storyBoard instantiateViewControllerWithIdentifier:@"Table"];

    NSArray *viewControllers = @[firstVC, tableVC];

    [super setupWithViewControllers:viewControllers];

    //this will cause a crash
    self.selectedIndex = 1;

}

@EnD

Throws:

2013-09-03 14:35:32.599 NGSegmentedViewController IB example[17196:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Children view controllers (null) and <UITableViewController: 0x811eb00> must have a common parent view controller when calling -[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]'
*** First throw call stack:
(0x15c0012 0x12cde7e 0x15bfdeb 0x306368 0xc99e 0x8e53 0xde1d 0x430de9 0x65c48a 0x65c603 0x214d7e 0x215002 0x213ed6 0x225315 0x22624b 0x217cf8 0x28e5df9 0x28e5ad0 0x1535bf5 0x1535962 0x1566bb6 0x1565f44 0x1565e1b 0x2137da 0x21565c 0x877d 0x261d725)
libc++abi.dylib: terminate called throwing an exception

I believe this is caused by calling the 'changeViewController' before view is in a window / controller hierarchy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.