Has anyone seen an implementation of an "accordion" (maybe called "animated outline") view for the iPhone? I found an example project for Cocoa, but before trying a port, I was hoping that someone has invented the wheel already.
To make it clear, in a UIView, consider a stack of sections, each containing a header, and then some contents. When the user touches the header (or through some message/event), if the section is already open => close it; if the section is closed => open it and close any other open section. An example in jQuery looks like: http://docs.jquery.com/UI/Accordion
In my case, I'd want to be able to put any UIView contents in each section.
I'd be interested in just seeing some real apps who have implemented this - just to know it's possible!
I would just use a UITableView, make each cell's height depend on whether or not it's "open" and then go from there. It's easy to resize the rows and you could just make the total height for the combined cells be the available height in the UITableView so that it looks like an accordion more than just a table.
This is a quick hack that should work, but in your UITableViewController subclass's .h file:
And in the .m file put something like:
This will basically take 4 rows and turn them into collapsable sections where selecting one row will expand it to 240 pixels and collapse all other rows to 40. You can change all of those numbers and figure out the sections and do whatever else you'd like with it.
I've tried this out and it works. You can then complete it by adding the other content to your cell creation code to add whatever you'd like to a section (including possibly a scrolling UITextView if you'd like).
Here's the
CollapsingTableViewDelegate
class that I'm currently working with to do this. This only works with static table content.You supply the
CollapsingTableCellDelegate
implementation to this class, which must know how to compute the collapsed and expanded sizes of each row, and how to create aUIView
for each row. The view stays the same whether collapsed or expanded, so that the top sliver of each row's view serves as that row's clickable header.You then make this class the datasource and delegate for your
UITableView
.Header file
CollapsingTableViewDelegate.h
:and source file
CollapsingTableViewDelegate.m
:Not perfection, but seems to basically work for me.
I found this code: A simple implementation of accordion..
https://github.com/kuon/ios-example-accordion
I hope this will help some one..
I found this example here if anyone is interested.
http://www.cocoanetics.com/2011/03/expandingcollapsing-tableview-sections/
Every solution that I found was using UITableView, which didn't work for me, because I didn't display tabular data. This is why I created AccordionView control. Usage is pretty straightforward:
In real life it looks like this:
Black bars are headers and you can customize them all you want (I'm using Three20).
I just stumbled across this and found mjdth's solution very straight forward and helpful. However, you might want to use
instead of the propoesed
reloadSections
method as the reload rows gives you a much smoother transition.