Giter VIP home page Giter VIP logo

Comments (9)

wtmoose avatar wtmoose commented on May 29, 2024

In the Outline sample project, "Heading 1.1" is a "synchronously and lazily loaded child". When I click "Heading 1.1" for the first time, I see NO passed in for collapsed as expected. More importantly, the UI behaves as you would expect.

Could you elaborate a bit or give me more detailed reproduction steps?

from tlindexpathtools.

wtmoose avatar wtmoose commented on May 29, 2024

I think I see what's going on. It seems your node is initialized to expanded (with zero children). So the first time you tap it, it gets collapsed. You just need to initialize the node to be collapsed. You would do that through the collapsedNodeIdentifiers argument of the data model initializer:

self.dataModel = [[TLTreeDataModel alloc] initWithTreeItems:self.treeItems collapsedNodeIdentifiers:<initial collapsed node identifiers>];

Collapsing a node collapses all child nodes. So you just need to include the identifier of your node or one of it's ancestors.

from tlindexpathtools.

ebgraham avatar ebgraham commented on May 29, 2024

This is probably the issue. I call initWithTreeItems:collapseNodeIdentifiers: when setting up the level 0 nodes in viewDidLoad, but not sure where to call this when lazy loading the child nodes in willChangeNode.

I've pasted the relevant code I'm using to help identify the issue here: http://pastebin.com/47sFYfeN

from tlindexpathtools.

wtmoose avatar wtmoose commented on May 29, 2024

OK, I got it now. Lazy loaded nodes default to expanded. I need to provide a way to specify their initial expanded/collapsed state. I'll look into it.

from tlindexpathtools.

wtmoose avatar wtmoose commented on May 29, 2024

Fixed. Now you can specify the initial collapsed state of lazy loaded child nodes. This involved some API changes, so you'll need to make some minor updates to your code. Here is a run-down of the changes:

  1. Collapsed node identifiers are now specified as an NSArray instead of an NSSet. This change was made to simplify coding since NSArray can be specified as a literal like @[item1, item 2, ...] while NSSet can't.
  2. The [TLTreeTableViewController setNewVersionOfItem:] method now takes an additional argument collapsedChildNodeIdentifiers, which provides the opportunity to initialize the collapsed state of lazy loaded child nodes.
  3. The willChangeNode delegate method no longer has a return value. So for the synchronous case, instead of returning the new tree item, you call setNewVersionOfItem from within willChangeNode. This makes the synchronous and asynchronous cases more consistent.
  4. The convenience method [TLIndexPathItem identifiersForIndexPathItems:] was added to simplify creating arrays of item identifiers. So now, the child identifiers for a given tree item can be created using [TLIndexPathItem identifiersForIndexPathItems:treeItem.childItems].

The example project was updated to incorporate all of the above changes.

from tlindexpathtools.

ebgraham avatar ebgraham commented on May 29, 2024

Implemented the changes and the issues is resolved. I have more questions about combining some of your library features, like getting dynamic heights with this, search working, and styling cells. Do you prefer that I open questions on StackOverflow so that it is visible to the community and your library gets exposure?

from tlindexpathtools.

ebgraham avatar ebgraham commented on May 29, 2024

Also noticed an issue with the cell remaining selected when clicked (highlighted in blue as the default behavior).

from tlindexpathtools.

wtmoose avatar wtmoose commented on May 29, 2024

Great. Yes, I do think the visibility on StackOverflow would help the library gain some traction.

from tlindexpathtools.

wtmoose avatar wtmoose commented on May 29, 2024

I forgot to mention the highlight. I changed the behavior because, in the spirit of keeping things light-weight and focused, I don't think the library should be responsible for it. The behavior could vary by app. So what you should do is override didSelectRowAtIndexPath like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [super tableView:tableView didSelectRowAtIndexPath:indexPath];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

And if you don't want leaf nodes to be selectable at all, you can do this:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TLIndexPathTreeItem *item = [self.indexPathController.dataModel itemAtIndexPath:indexPath];
    return item.childItems == nil ? nil : indexPath;
}

Perhaps it would make sense to include these in the sample project with some comments?

from tlindexpathtools.

Related Issues (20)

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.