Git Product home page Git Product logo

gcretractablesectioncontroller-master's Introduction

GCRetractableSectionController

GCRetractableSectionController is an helper class that let you make easily section of UITableView that detract and contract when tapped.

Usage

(See the demo project included)

Creation and customization

First thing you need to do is subclass GCRetractableSectionController to have your own section controller. (You can also look at GCArraySectionController, a drop-in subclass that you can use right away, available in the demo project.)

The basics things you need to overwrite are the following.

@property (nonatomic, copy, readonly) NSString* title;
@property (nonatomic, readonly) NSUInteger contentNumberOfRow;
- (NSString*) titleContentForRow:(NSUInteger) row;

The title property represent the title of the section. The title is shown in the main cell when the section controller is closed. The contentNumberOfRow should return the number of rows of content in your section (the title cell is not content). You also overwrite titleContentForRow: to provide the title of your content cells.

See the GCSimpleSectionController example in the demo project.

To react to selection of your content, you should overwrite in your section controller this method.

- (void)didSelectContentCellAtRow:(NSUInteger)row;

You can also change have more control on the content of your cells by overwriting the following methods. Look at the GCCustomSectionController in the demo project for more details.

- (UITableViewCell *)cellForRow:(NSUInteger)row;
- (UITableViewCell *)titleCell;
- (UITableViewCell *)contentCellForRow:(NSUInteger)row;

UITableView’s dataSource usage

When your GCRetractableSectionController is ready, you need to use it in your UIViewController.

You initialize your subclass by providing your UIViewController. You UIViewController must respond to the ‘tableView’ selector and return a UITableView. You’ll probably want to save that section controller as an ivar.

YourSectionController* sectionController = [[YourSectionController alloc] initWithViewController:self];

GCRetractableSectionController provide simple method for you to use in you UITableView ’s dataSource. An example usage follow.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    GCRetractableSectionController* sectionController = /*Your section controller ivar*/;
    return sectionController.numberOfRow;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    GCRetractableSectionController* sectionController = /*Your section controller ivar*/;
    return [sectionController cellForRow:indexPath.row];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    GCRetractableSectionController* sectionController = /*Your section controller ivar*/;
    return [sectionController didSelectCellAtRow:indexPath.row];
}

gcretractablesectioncontroller-master's People

Contributors

zggithub 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.