GithubHelp home page GithubHelp logo

janak-nirmal / ios-sdnestedtable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robelkin/ios-sdnestedtables

1.0 2.0 0.0 355 KB

Obj-C module built on UITableView for creating a 2-level nested list UI control. iOS 4.0+

License: Other

ios-sdnestedtable's Introduction

SDNestedTable

Obj-C module built on UITableView for creating a 2-level nested list UI control, iOS 4.0+.

SDNestedTable Screenshot 1 - iPhone Portrait   SDNestedTable Screenshot 2 - iPhone Portrait   SDNestedTable Screenshot 3 - iPhone Portrait   SDNestedTable Screenshot 4 - iPhone Portrait   SDNestedTable Screenshot 1 - iPad Landscape

How To:

Create a subclass of SDNestedTable. You can call either init or initWithNibName:bundle:. Calling init will call initWithNibName:@"SDNestedTableView" bundle:nil.

Then implement the following convenience methods:


### Filling the views

- (NSInteger)mainTable:(UITableView *)mainTable numberOfItemsInSection:(NSInteger)section;

here you can set the amount of Items in your Main table:

- (NSInteger)mainTable:(UITableView *)mainTable numberOfItemsInSection:(NSInteger)section
{
    return 15; // amount of Main Items
}

- (NSInteger)mainTable:(UITableView *)mainTable numberOfSubItemsforItem:(SDGroupCell *)item atIndexPath:(NSIndexPath *)indexPath;

here you can set the amount of Sub Items for each Item in the Main table:

- (NSInteger)mainTable:(UITableView *)mainTable numberOfSubItemsforItem:(SDGroupCell *)item atIndexPath:(NSIndexPath *)indexPath
{
    return 3; // amount of Sub Items for each Main Item
}

- (SDGroupCell *)mainTable:(UITableView *)mainTable setItem:(SDGroupCell *)item forRowAtIndexPath:(NSIndexPath *)indexPath;

here you can set the Item's cell attributes:

- (SDGroupCell *)mainTable:(UITableView *)mainTable setItem:(SDGroupCell *)item forRowAtIndexPath:(NSIndexPath *)indexPath
{
    item.itemText.text = [NSString stringWithFormat:@"My Main Item %u", indexPath.row +1];
    return item;
}

- (SDSubCell *)item:(SDGroupCell *)item setSubItem:(SDSubCell *)subItem forRowAtIndexPath:(NSIndexPath *)indexPath;

here you can set the Sub Item's cell attributes:

- (SDSubCell *)item:(SDGroupCell *)item setSubItem:(SDSubCell *)subItem forRowAtIndexPath:(NSIndexPath *)indexPath
{
    subItem.itemText.text = [NSString stringWithFormat:@"My Sub Item %u", indexPath.row +1];
    return subItem;
}

### Delegate methods

SDNestedTable implements the SDNestedTableDelegate protocol, however you are free to implement the following methods yourself if they will provide useful information.

- (void)mainTable:(UITableView *)mainTable itemDidChange:(SDGroupCell *)item;

this is called when the Item state changes, here you can manage behavior according to the Item state:

- (void)mainTable:(UITableView *)mainTable itemDidChange:(SDGroupCell *)item
{
	SelectableCellState state = item.selectableCellState;
	NSIndexPath *indexPath = [self.tableView indexPathForCell:item];
    switch (state) {
        case Checked:
        	// do stuff
            break;
        case Unchecked:
        	// do stuff
            break;
        case Halfchecked:
        	// do stuff
            break;
        default:
        break;
    }
}

- (void) item:(SDGroupCell *)item subItemDidChange:(SDSelectableCell *)subItem;

this is called when the Sub Item state changes, here you can manage behavior according to the Sub Item state:

- (void) item:(SDGroupCell *)item subItemDidChange:(SDSelectableCell *)subItem
{
    SelectableCellState state = subItem.selectableCellState;
    NSIndexPath *indexPath = [item.subTable indexPathForCell:subItem];
    switch (state) {
        case Checked:
        	// do stuff
            break;
        case Unchecked:
        	// do stuff
            break;
        default:
            break;
    }
}

### Other methods

- (void)expandingItem:(SDGroupCell *)item withIndexPath:(NSIndexPath *)indexPath;

this is called when a Main Item starts collapsing, here you can manage behavior according to this event:

- (void)expandingItem:(SDGroupCell *)item withIndexPath:(NSIndexPath *)indexPath
{
	// do stuff
}

- (void)collapsingItem:(SDGroupCell *)item withIndexPath:(NSIndexPath *)indexPath;

this is called when a Main Item starts expanding, here you can manage behavior according to this event:

- (void)collapsingItem:(SDGroupCell *)item withIndexPath:(NSIndexPath *)indexPath 
{
	// do stuff
}

### Table Items properties

Main Items & Sub Items

SDNestedTableViewController *parentTable

SelectableCellState selectableCellState

UILabel *itemText

Main Items Only

UITableView *subTable

BOOL isExpanded

// all items

item.parentTable

item.selectableCellState

item.itemText


// only Main Items

item.subTable

item.isExpanded

Roadmap/Feature Ideas

Can't use custom classes cleanly in place of the default cells

Cell heights are tightly coupled to default classes

Provide more delegate methods

Pass "tapped" event info to the delegate methods in order to know if the Item changed state passively or actively

ios-sdnestedtable's People

Contributors

morekid avatar robelkin avatar

Stargazers

Janak Nirmal avatar

Watchers

James Cloos avatar Janak Nirmal 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.