Code Monkey home page Code Monkey logo

ratreeview's Introduction

RATreeView (iOS 7.0+, tvOS 9.0+)

👷 Project created and maintained by Rafał Augustyniak. You can find me on twitter (@RaAugustyniak).

Introduction

Twitter: @raaugustyniak Build Status Carthage compatible CocoaPods Platform License: MIT

iOS tvOS

RATreeView is a class designed to provide easy and pleasant way to work with tree views on iOS and tvOS. It works as a wrapper for the UITableView, defining its own delegate and data source methods which make working with tree data structures really easy.

RATreeView is highly customizable and has a lot of features.

Installation

CocoaPods

CocoaPods is the recommended way to add RATreeView to your project.

  1. Add additional entry to your Podfile.
pod "RATreeView", "~> 2.1.2"
  1. Install Pod(s) running pod install command.
  2. Include RATreeView using #import <RATreeView.h>.

###Source files

  1. Downloaded the latest version of the library using link.
  2. Copy content of the downloaded (and unzipped) zip file into your project by dragging it into Project's navigator files structure.

Requirements

  • Xcode 5
  • iOS 7 or newer/tvOS 9 or newer

Usage

Check out the demo for example usage of library. Make sure you read the RATreeView documentation on Cocoa Docs.

Basics

  1. Add following import in file of your project when you want to use RATreeView:

    // In case you are using RATreeView with CocoaPods
    #import <RATreeView.h>
    // In case you are using RATreeView by simply copying 
    // source files of the RATreeView into your project
    #import "RATreeView.h"
  2. Simplest way to initialize and configure RATreeView:

    RATreeView *treeView = [[RATreeView alloc] initWithFrame:self.view.bounds];
    treeView.delegate = self;
    treeView.dataSource = self;       
    [self.view addSubview:treeView];
    [treeView reloadData];
  3. Implement required methods of the RATreeView's data source:

    - (NSInteger)treeView:(RATreeView *)treeView numberOfChildrenOfItem:(id)item
    {
        return item ? 3 : 0;
    }
    - (UITableViewCell *)treeView:(RATreeView *)treeView cellForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo
    {
       // create and configure cell for *item*
       return cell
    }
    - (id)treeView:(RATreeView *)treeView child:(NSInteger)index ofItem:(id)item
    {
       return @(index);
    }

Adding Pull to Refresh control

Adding pull to refresh gesture is really easy using RATreeView and standard UIRefreshControl control.

UIRefreshControl *refreshControl = [UIRefreshControl new];
[refreshControl addTarget:self action:@selector(refreshControlChanged:) forControlEvents:UIControlEventValueChanged];
[treeView.scrollView addSubview:refreshControl];

Documentation

Documentation is available on CocoaPods.

TODO

  • Better delegate callbacks in case of recursive collapse and expand operations.
  • Improved documentation.
  • Unit tests.
  • Re-order rows feature.

Author

RATreeView was created by Rafał Augustyniak. You can find me on twitter (@RaAugustyniak).

Release Notes

Information about newer versions of the library can be found in the releases section of the repository.

Version 1.0.2

  • Fixed bug in select and deselect operations.
  • Fixed bug in recursive expand operation (via @Arrnas).

Version 1.0.1

  • Fixed bug in recursive expand operation.

Version 1.0.0

  • Improved performance.
  • Added recursive expand operation. It can be performed by using expandRowForItem: expandChildren:withRowAnimation: method. Default behavior is non recursive expand.
  • Added recursive collapse operation. It can be performed by using collapseRowForItem: expandChildren:withRowAnimation: method. Default behavior is non recursive collapse.
  • Fixed bug in itemForRowAtPoint: method when passed point isn't inside any cell.

Version 0.9.2

  • Fixed bug in endUpdates method.

Version 0.9.1

  • Fixed behaviour of treeView:willSelectRowForItem: delegate method.

Version 0.9.0

  • Added possiblity to change content of the RATreeView dynamically. Possible row operations:
    • additions
    • deletions
    • repositions
  • Added additional 'cell accessing' methods.
  • Removed RATreeNodeInfo class.
  • Added additional instance methods in RATreeView which substitute functionality provided by RATreeNodeInfo class.
  • Bug fixes.

License

MIT licensed, Copyright (c) 2014 Rafał Augustyniak, @RaAugustyniak

ratreeview's People

Contributors

anatols avatar antonholmquist avatar augustyniak avatar daikini avatar dduan avatar dumoko avatar kkebo avatar qoolloop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ratreeview's Issues

separatorInset crashes on iOS6

RATreeVIew contains

  • (UIEdgeInsets)separatorInset
    {
    return self.tableView.separatorInset;
    }
  • (void)setSeparatorInset:(UIEdgeInsets)separatorInset
    {
    self.tableView.separatorInset = separatorInset;
    }

that crash on iOS6

register class support for RATreeView

// Creating Table View Cells
- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0);
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);

simple implementation

- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier
{
  [self.tableView registerClass:cellClass forCellReuseIdentifier:identifier];
}

How can I delete rows in RATreeView?

I tried to use [self.treeView.tableView deleteRowsForIndexPaths:withRowAnimation:], but always crash:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (9) must be equal to the number of rows contained in that section before the update (9), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

Disable Auto scrolling to top

Hi,

i'm facing a problem, when i expand a cell the treeview automatically scrolls to top. I can't disable it using scrollsToTop or alwaysBounceVertical properties of tableview.

How can i disable this?

Thanks!

Adding open/closed disclosure to Cells

Thank you for such wonderful control.

This is not an issue, I was wondering is it possible to have UITableViewCell which was expanded, I checked following delegate method is being called whenever any tree is being expanded but was not able to understand how to access particular UITableViewCell from this method.

  • (void)treeView:(RATreeView *)treeView willExpandRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo

I want to add open/closed state using image to inform user regarding cell is expanded.
e.g.

tableViewCell.image = @"Opened" or tableViewCell.image = @"Closed"

Can you please assist ?

Thanks,

Use the titleForDeleteConfirmationButton..

Hi,

First of all, thanks for you lib.
I just used it to make a treeview, and every things working fine.
But i'd like now to be able to select an item (depth doesn't matter), I saw that there is a interested function which is the Delete button appearing when we slide Right > Left.
Is there a way to catch the button action ?
I'm a beginner in iOS programming and objective-C (started yesterday).

Thanks in advance,

typo in RATreeView.m

122: self.rowsExpandingAnimation = RATreeViewRowAnimationTop;
123: self.rowsExpandingAnimation = RATreeViewRowAnimationBottom;

should be

122: self.rowsExpandingAnimation = RATreeViewRowAnimationTop;
123: self.rowsCollapsingAnimation = RATreeViewRowAnimationBottom;

scrollViewDidScroll not called

If I implement - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ in the tableview delegate, the method is never called. Any idea how to get it called?

Reordering Table cells

Hi!
Thanks for such a great control. This is what i was looking for. Just wanted to ask, how i can reorder (drag/drop) cells. I couldn't find any delegate for that. Is it possible?

UIImage Indentation

Thank you for making such a wonderful control. When I add an image to my tableview cell, how can I achieve indentation of the image as well.

The separator line of previous cell disappears

The separator line of the cell above the tapped cell gets hidden.
Scenario: Tap on second cell of levelDepth 0, It open ups levelDepth1 for the same cell.
Tap again on the same cell (i.e levelDepth 0) It will close the levelDepth1 for the cell

Now observe the separator line of the previous cell. It is disappeared

How to get tableView height ?

I have this RATreeView inside a collection view cell.
When the table view cell expands I want to increase the collection view cell height.
But how can i get the height of the tableView after expanding so that i can expand the collection view cell to same amount.
In RATreeView i can only access contentSize which is not giving proper results.
Thanks

treeNodeInfo.treeDepthLevel is always zero

In my Application I am using the treeDepthLevel property of RATreeNodeInfo to get the key for the next level children But to my surprise that property is always equal to zero instead of the current node level

Word Wrapping

When the labels get too long, they get cut off with ellipses "...", but if it's necessary to see the whole label, wrapping texts could be useful. I have tried to implement it to no avail. Do you have some suggestions as to a solution for this?

Crash when depth level greater than 3

In my project i want to have 4 level tree so i used this source code but after adding 4 level tree my app crash when collapsing a cell with animation. following is the crash report found in my project

"Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cell animation stop fraction must be greater than start fraction' "

And My Tree is like following
_First_level_item 1
_______ Second_level_item 1
_____________Third_level_item 1
_____________Third_level_item 2
_____________Third_level_item 3
_____________Third_level_item 4
___________________Fourth_level_item 1
___________________Fourth_level_item 2
__________________*Fourth_level_item 3

Grouped table view

Does it currently support Grouped style tableview? I've set the style to RATreeViewStyleGrouped, but all my data are in the same section.

BTW, thanks for the great work 👍

丫的,你这内存泄露太严重了!

我用了你的ratreeview做的cell,然后用的sdwebimage加载图片,发现滑动cell 的时候内存泄露太严重了。耽误了我的项目进度,丫的赔我钱吧!
而且滑动的时候还卡,耽误我项目进度,丫的赔我钱!

RATreeViewRowAnimation equivalent for UITableViewRowAnimationFade

There is no enumeration that corresponds to UITableViewRowAnimationFade enumeration in RATreeViewRowAnimation. I had to add it and make related conversion myself.

What's the reason of specifically excluding fade animation from animation alternatives?

Also I have a more general question. What's the reason behind defining your own enumerations for almost all enumerations that UITableView defines? I didn't see any different usage for them, you're requesting your own enumeration key, then convert it to UITableView's corresponding enumerations that everybody is familiar with.

I think it adds redundancy to the component and decrease simplicity.

What you think about that?

Using RATreeView with CoreData

Hi thanks for developing this great api.
I want to feed RATreeView with items which I get from sqlite db with core data.
FetchedResultsController needs sectionIndex. which I can't get from data source method.
do you know how can I provide sectionIndex?
would you mind provide a sample of treeView using coreData?

How to delete rows from RATreeView?

It was so easy to use RATreeView in my app and it looks great. Thank you for such a useful bit of code.

The earlier closed issue doesn't apply anymore as there is no public visibility of the tableview property in RATreeView.

There seems to be no way of deleting rows. The comment in the header file suggests there is but there is no selector.

Retain cycle - make parentTreeNode property weak

In RATreeNode:

@property (strong, nonatomic, readonly) RATreeNodeInfo *treeNodeInfo;

Should be:

@property (weak, nonatomic, readonly) RATreeNodeInfo *treeNodeInfo;

There's a retain cycle here and it's causing whatever model you are using for your tree to never get dealloced.

Thanks!

cellForItem method called before expanding was completed

When the user taps on a cell and it expands. The method cellForItem is called again but this is done before the expanding was completed. Therefore the expanded property of treeNodeInfo is always NO. This makes it impossible to return another TableViewCell for expanded state.

can't find on pods

pod search RATreeView
[!] Unable to find a pod with name matching `RATreeView'

Hide unused cell

Is is also possible to hide unused cell? In the old tableview, I could set the footer height to some very small number, say, 0.01f and then create an empty uiview as the footer. Any plan to implement similar functionality?

expandRowForItem

Thanks for creating this great component!
One issue i have is when i try to use the expandRowForItem this only works for items in the highest leaf, not with children :( Any suggestions to fix this?

Default select child item

how to implement to expand the father first child menu item by default when i click father menu item ?
Is there anybody know that?

Expand All

Is there a way to expand all the nested cell with one call ?

expandRowForItem crash when treeNode.expanded is YES

I try to call the expandRowForItem:, I get a crash that table view try to insert rows.

I think it is that the row is expanded, and I expand it again!

I can not access the treeNode for the item, so I can not get the expand status.

I hope you can add some code like this:

- (void)expandRowForItem:(id)item withRowAnimation:(RATreeViewRowAnimation)animation
{
  NSInteger index = [self.treeNodeCollectionController indexForItem:item];
  RATreeNode *treeNode = [self.treeNodeCollectionController treeNodeForIndex:index];
+    if (treeNode.expanded) {
+        return;
+    }
  [self expandCellForTreeNode:treeNode withRowAnimation:animation];
}

WillSelectRow item value incorrect

In RATreeView+TableViewDelegate.m:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

The line:

id item = [self.delegate treeView:self willSelectRowForItem:treeNode treeNodeInfo:[treeNode treeNodeInfo]];

Should probably be:

id item = [self.delegate treeView:self willSelectRowForItem:treeNode.item treeNodeInfo:[treeNode treeNodeInfo]];

Unless my two weeks of Objective C programming is leading me astray, which it may be. However, making this change fixed my issues with handling this event.

button index

How to find button index in RATreeView.i have implement this lib. in my project but how to set tag and find index of button (V)in this lib.
screen shot 2014-02-03 at 2 37 59 pm

initWithFrame not working for custom sizes

I have tried many combination but couldn't get working one

RATreeView *treeView = [[RATreeView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];

RATreeView *treeView = [[RATreeView alloc] initWithFrame:CGRectMake(0, 0, 320, 300) style:RATreeViewStylePlain];

both not working, then I have created xib with view, assign RATreeView, connect with code as IBOutlet and still not working for custom sizes

All of this examples not working if you wanna smaller size for view, is there any fix for this or I making something wrong???
Every time they are in full screen mode :(

Thx

table cell separator not showing

Using the sample app running iOS 7.x. Expand Phones section and expand Computers section.

ios simulator screen shot nov 23 2013 12 25 04 pm

Close Phones section and then close Computers section (order is important). The cell separator between Phones and Computers section is not showing.

ios simulator screen shot nov 23 2013 12 25 10 pm

not find button index in treeview

I am implement RATreeView in my Project . I create custom cell in which button for first level.So my issue is how to find which button is click from firstlevel in RATreeview . In tableview we have set tag of button and get index of button but how to done in RAtreeView

RATreeView itemForCell

Hi,

First I would like to say thanks for the great work this is a really awesome library to use.

I've started implementing your RATreeView and have come across a situation where I need to handle a tap gesture on a custom View that I use as the cell contentView and all works fine.

I however run into an issue when I handle the tap gesture on a button in the view as I am able to get the UITableViewCell which it originated from but need to then get access to the corresponding "item" in the RATreeView.

I basically need a method with signature: - (id) itemForCell: (UITableViewCell *) cell.

I am writing to you for the following reasons:

  • I really appreciate the quality and effort of the code you have done and would prefer to keep on using further version of it via pods. This however leaves me with a problem, if I Implement my own solution within RATreeView class then I wont be able to get the dependency updated via pods.
  • If you deem this useful it could perhaps be added to the library thus removing the need for us to maintain a fork of the project.

Regards
Rory Beling

reloadData not work

hi
reloadData method not work.
and after that numberOfChildrenOfItem of datasource not call.

for example add this code in end of viewDidLoad of your Demo Project

walls = [RADataObject dataObjectWithName:@"Walls1" children:nil];
self.data = [NSArray arrayWithObjects:phone, computer, car, bike, house, flats, motorbike, drinks, food, sweets, watches, walls, nil];
[treeView reloadData];

you will see still Wall shown as last object of table view instead of Walls1

expandRowForItem won't call the delegate: treeView: willExpandRowForItem: treeNodeInfo:

just use the demo, when call

  • (void)expandRowForItem:(id)item withRowAnimation:(RATreeViewRowAnimation)animation

but the delegate of

  • (void)treeView:(RATreeView *)treeView willExpandRowForItem:(id)item treeNodeInfo:(RATreeNodeInfo *)treeNodeInfo;

won't be called.

I found that this delegate will be called in

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

in RATreeView+TableViewDelegate.

indexPathForCell

The view should probably have indexPathForCell and/or itemForCell added to it. This would make it easier to get the associated item on a touch event, say from a button added to the cell. And there are many times when an item is available and a cell is needed.

Dynamically changing the tableview Cells...

First off, thank you so much for offering this project code on here. It's exactly what I was looking for.

I'm sure it's just me but I'm having issues trying to dynamically change the cell between a default style to my own custom style when the user expands a parent cell.
I've created my own subclasses uitableviewcell. I can get it to change between default style cells but I can't find a way to init my custom one and change the cell in the "willexpandrow" method.

Can you offer any help or is this not possible?

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.