Closed kmav closed 8 years ago
Just like the examples, you need a class that implements UIViewController. In storyboard you can create a blank UIViewController instance. You can add toolbars, etc; and set up your segues. In the class implementation, manually add your RATreeview as a subview in ViewDidLoad (just like the example).
Thank you for your reply :)
I have already integrated with simple view controller storyboard object following the example. But, I think that the example is more focused on a programmatic approach, or I cannot understand how to integrate it in storyboards. Please find below my specific issues:
Please note that what I see in the example is more related on how to create a tableview programmatically as described here
@kmav I don't think you can really use RATreeView
as you'd like with storyboards, because it doesn't subclass UITableView, but UIView.
So you need to take you UIView reference and then set everything up programmatically in viewDidLoad
. Found a (much less popular) alternative library that subclasses UITableView, going to give using it a shot instead.
@AndrewSB Thank you for your feedback and the information for alternative library. In RATreeView library there is an RATableView class (private?) that inherits from UITableView. I wonder if I can use that to establish the integration. Also, regarding segues, i.e. opening a detail view when the user touches on a tree row, what I have noticed is that when you touch a tree row the children of that row are expanding/unfold. Can I change the functionality of touching a row to e.g. open a detail view and use some other control for expanding the children, or is this not permitted at all (this is how it is designed)?
I apologize for missing your response to my initial comment.
When using a navigation controller you must use the "embed in" command in storyboard for any child view controllers to automatically add the toolbar and prevent overlap over sub views.
Regarding the expand/collapse functionality - implement the "should expand cell" and "should collapse cell" delegate methods to always return No. That will turn off the automatic expand/collapse action.
In my programs I use an addition style button that is only displayed by cells with children. Tapping that button calls "expand" or "collapse" on the cell, and reloads the tree view. I use delegate method implementation in the top UIViewController class just like the example. If you implement it there you can make calls to the RATreeView directly, where as if you implemented the method down in your cell class you'd have to pass messages back up to the parent to trigger tree reloads.
Capture the tapping action like a normal tableview cell with "didselect"
@kmav I don't think it's possible to use the private internal class to make a table. I ended up just rolling my own solution for this, since I only needed one level of collapsibility it wasn't too bad.
Can share my solution if it would be of any help to you
@joshjack and @AndrewSB thank you so much for your kind assistance and explanations that show me the direction to follow. I will experiment a while and get back to you.
@joshjack After inactivating default shouldExpand/Collapse, what do you call to reproduce their behaviour with the '+' style button?
@kmav it's a tree view command, something like [_mytreeview expandrowforcell:cell];
Because this is done as a code block using weak self inside the cell creation method (just like the demos), you have access to both the cell and the parent tree view.
@joshjack I have implemented most of what you suggested related to collapse/expand with an addition symbol and it works! performseguewithidentifier crashes, because, I think, as @AndrewSB pointed out, RATreeView cannot be used as a UITableView, so I cannot create in storyboards a TableView object and connect it to my RATreeView (I did not even tried). So, I cannot have a cell view to start ctrl-drag from it to my next detail scene.
What I did for the moment, is a programmatic solution in didSelectRowForItem as below:
- (void)treeView:(RATreeView *)treeView didSelectRowForItem:(id)item {
TeamTableViewController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"UnitTeam"];
if (detailViewController) {
detailViewController.activeUser = self.activeUser;
OrgUnitsChildren *dataObject = [self.treeView itemForSelectedRow];
NSLog(@"... with unitID %d", (int)dataObject.unitID);
[detailViewController setActiveUnit:[[Unit alloc] initWithName:dataObject.name unitID:[NSString stringWithFormat:@"%f",dataObject.unitID] lat:[NSString stringWithFormat:@"%f",dataObject.latitude] lng:[NSString stringWithFormat:@"%f",dataObject.longitude]]];
}
[self.navigationController pushViewController: detailViewController animated:YES];
}
As for navigation controller and embed-in, this is how I use it. I have a series of scenes until RATreeView that the first of which is embed-in navigation controller. But, in connecting RATreeView ViewController scene with the next I cannot use segues at the moment as I said and the possibility that I have is using the code in didSelectRowForItem. In this way the navigationbar and title work. However, I still have issues for 3 first/last cells in RATreeView that are squeezed in bottom of scrollview of RATreeView ViewController. Finally, I think that in the provided example, the storyboard scenes are not used at all. There is a code in appdelegate that starts the RATreeView.
@kmav here's an alternate approach:
- (void)treeView:(RATreeView *)treeView didSelectRowForItem:(id)item {
[self performSegueWithIdentifier:@"segueToTeamTBVC" sender:self];
}
You'll still have to pass the "activeUser" somehow (I use a singleton class for that).
Last note - this line:
`OrgUnitsChildren dataObject = [self.treeView itemForSelectedRow]; should be simplified to:
OrgUnitsChildren *dataObject = item;`
@joshjack Yes. You have right! I failed yesterday with that ctrl-click and dragging, just due to bad arrangement of my scenes!!! Thank you very much for your help.
Is there any way to integrate with storyboards? For example, if there was some integration with tableviewcontroller then we could create segues more easy.