Code Monkey home page Code Monkey logo

dsnestedaccordion's Introduction

DSNestedAccordion

A nested accordion view for Cocoa Touch

Demo

DSNestedAccordion iPhone demo

Current Version

Version: 0.1.0

Under the Hood

  • Pluggable and decoupled from user interface layer
  • Supports infinite levels of nesting
  • Uses ARC (Automatic Reference Counting)

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Extend DSNestedAccordionHandler

DSNestedAccordionHandler provides abstract implementation of UITableViewDataSource and UITableViewDelegate with support for nesting table views

#import "DSNestedAccordionHandler.h"

@interface DSBeerTableViewHandler : DSNestedAccordionHandler

@end

Implement 3 datasource methods

- (NSInteger)noOfRowsInRootLevel;

- (NSInteger)tableView:(UITableView *)view noOfChildRowsForCellAtPath:(DSCellPath *)path;

- (UITableViewCell *)tableView:(UITableView *)view cellForPath:(DSCellPath *)path;

DSCellPath represents the traversal path to the cell from the root level within a nested model. levelIndexes array property will hold the indices of the parent cells at each nesting level.

For example, levelIndexes having a value @[1, 2, 0] would identify the path vertibrate > bird > duck in the below example data.

  • invertebrate
  • worm
    • fluke, hookworm, earthworm
  • arthropod
    • crab, spider, shrimp
  • vertebrate
  • amphibian
    • frog, crocodile
  • mammal
    • dog, cat, lion, tiger
  • bird
    • duck, pigeon, peacock, parrot

Example implementation

- (NSInteger)noOfRowsInRootLevel {
    return _beers.allFlavors.count;
}
- (NSInteger)tableView:(UITableView *)view noOfChildRowsForCellAtPath:(DSCellPath *)path {
    switch (path.levelIndexes.count) {
        case 1:
            return [self noOfBeerStylesForFlavorAtIndex:[path.levelIndexes[0] integerValue]];
        case 2:
            return [self noOfNotableBeerStylesForStyleAtIndex:[path.levelIndexes[1] integerValue] withFlavorAtIndex:[path.levelIndexes[0] integerValue]];
        default:
            0;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForPath:(DSCellPath *)path {
    switch (path.levelIndexes.count) {
        case 1:
            return [self tableView:tableView cellForBeerFlavorAtIndex:[path.levelIndexes[0] integerValue]];
        case 2:
            return [self tableView:tableView cellForBeerStyleAtIndex:[path.levelIndexes[1] integerValue] withFlavorWithIndex:[path.levelIndexes[0] integerValue]];
        default:
            return [self tableView:tableView cellForNotableBeerStyleAtIndex:[path.levelIndexes[2] integerValue] ofStyleWithIndex:[path.levelIndexes[1] integerValue] withFlavorWithIndex:[path.levelIndexes[0] integerValue]];
    }
}

Requirements

iOS 6

Installation

DSNestedAccordion is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DSNestedAccordion"

Author

deepan, [email protected]

Contact

If you have any questions comments or suggestions, send me a message. If you find a bug, or want to submit a pull request, let me know.

License

DSNestedAccordion is available under the MIT license. See the LICENSE file for more info.

Credits

The demo concept was inspired from this article published by http://www.splendidtable.org/

dsnestedaccordion's People

Contributors

barrettj avatar deepan avatar

Watchers

 avatar

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.