iOS- TableViewCell expand/collapse - iphone

i want to create a a TableView with expand/collapse cells, and i thought 2 ways to achieve that:
Play with the heightForRowAtIndexPath
Create 2 different cell, with different identifier, and each time load the right one.
I want the cell to expand/collapse with animation, and the user can expand more then one cell.
Which one is better?
Thanks in advance!

Depends on your cell, before and after collapsing, and whether you want to animate it or not.
Options:
If the contents are the same, or with some small additions, and you wanna animate it. Use this option.
If the contents changes dramatically, go with this option. And I'm not sure if animation in this case is easy.
Good luck, need more help, let me know! ;D

I think you want this: https://github.com/seletz/CocoaTreeViewExample
I have made a expandable/collapsable treeview using the same code that is looking like this in my application now:

I was after something similar, I wanted to be able to show and hide contextMenu for a table view cell. So I ended up using just one cell for both expanded and collapsed state, and I had a "context menu subview" (that's what I wanted for the expanded look) and updated it's frame for the animation.
The trick is that when you want to expand/collapse you cell with a nice animation you'd better use beginUpdates and endUpdates instead of reloadData or reloadRowsAtIndexPaths:withRowAnimation: methods. Something like that:
// setContextMenuHidden:animated: updates frame and alpha for the context menu
// view (which is a subview of cell content view)
[cell setContextMenuHidden:NO animated:YES];
[self.tableView beginUpdates];
[self.tableView endUpdates];

Related

How to manage such animation in UITableView or with any other control?

i want to implement delete row with animation like this video.
Now deleting of row is easy task now i have question regarding how to manage animation like above video with UITable or any other control.
i refer some instance method. for tableview.
But in this, i am not getting how to manage animation like move row on touch in tableview.
Any suggestion appreciated.
Thanks
The animation would need to be a custom implementation. I would recommend having a subview on the UITableViewCell (the subview would be the red, the table view cell's background would be the black), and place a UIPanGestureRecognizer on the subview. You'd then need to move the subview as the user pans (in the gesture recognizer's method that is triggered), and do the math to know when the row should be deleted. Then you would just use the native iOS delete row method:
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
I found such cool custom control based on UITableView which provide exact animation i actually required.
You can found code here.

UITableView - Add subview to cell content view on row selection

How can I add an UIView as a subview in a cells contentView when the user has tapped the cell, and remove the same UIView when the user taps that cell again?
I am trying to make a list of photos in a UITableView with expand/collapse button. The UIView that I want to add is the container of photo's information. Instagram accomplished it, but I cant figure out how to do it
Please help me guys :)
Thanks!!!
I don't think you want to add a subview to the cell, but you want to add another cell to the already existing table. This way, you can achieve an "expand/collapse" feel to your table by using insertRowsAtIndexPaths:withRowAnimation:
Good luck!
Adding and removing the views in the cell should be easy enough inside didSelectRow, but you may need to keep track of which rows are in what state (big or small) by recording that in a mutable array. The bigger issue you will have is adjusting a cell's height, but look here for that.

UITableViewScrollPositionTop on the last UITableViewCell

I am having a hard time trying to make the very last UITableViewCell from my table to get to the UITableViewScrollPositionTop.
The behavior I would expect is:
On didSelectTableAtindexPath:lastindex, the table would bring the last cell all the way up to the top position... I would do whatever is needed, then, I could resume the positioning (pretty much like what happens when we use a textField inside the cell and the keyboard fires up)
Does anyone know how can we get that kind of behavior?
I got it by myself actually...
If anyone is having the same issue, here is what you should do:
right before using the scrollToRowAtIndexPath:atScrollPosition:animated:
use:
aTableView.contentInset = UIEdgeInsetsMake(aTableView.contentInset.top,
aTableView.contentInset.left,
aTableView.contentInset.bottom+300,
aTableView.contentInset.right);
do what you have to do and then:
aTableView.contentInset = UIEdgeInsetsMake(aTableView.contentInset.top,
aTableView.contentInset.left,
aTableView.contentInset.bottom-300,
aTableView.contentInset.right);
the only problem is that the comming back from the inset is not animated, but I guess you can set an animation to smooth the transition...
Use this delegate methods to scroll top or bottom
scrollToNearestSelectedRowAtScrollPosition:animated:
scrollToRowAtIndexPath:atScrollPosition:animated:
selectRowAtIndexPath:animated:scrollPosition:

iPhone - Smooth animation for UITableViewCell height change including content update [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can you animate a height change on a UITableViewCell when selected?
I have a table view into which where you click on a swich into a cell, many cells of the table view may change their height. It's a little bit complicated to compute which cells will change their size, so I'd like not to call twice the same code.
I have a heightForRowAtIndexPath method (this is the complicated one).
Is there a way to animate the cell grow or reduce feature without impacting the one that does not change ?
I've tried UIView Animations, reloadData for sections with animation, ... but I didn't find anything smooth.
I've tried to catch each cell that will have to change and call a reloadData with animation on each cell. It's near to work but the cells are updating one after the other. And as I said before, I don't want to do that because I must call twice the heightForRowAtIndexPath method.
What I'd like is something that can animated each cell that has a changing height with somthing like a grow or reduce movement, and not a fade one.
Do you know a way to do that ?
One more thing, the content of the cell is changing a little bit when size change (some text added, back color changing, and things like that)
UITableView has a neat trick to animate changes in cell heights: if you send an empty updates block to the table view, it won't insert or delete any cells, but it will still recalculate cell heights for the entire table. So even though this piece of code looks weird, it should do it:
[tableView beginUpdates];
[tableView endUpdates];
If you want to change the contents of the updated cells, too, you must add one or more calls to reloadRowsAtIndexPaths:withRowAnimation: to the updates block, of course.

Displaying dynamic subview in tableviewcell

After the user taps a tableview cell, I'd like to slide open a small view just below the cell . The first screenshot of these two apps show this:
Tweetie 2: http://itunes.apple.com/us/app/tweetie-2/id333903271?mt=8
Pastebot: http://itunes.apple.com/us/app/id344614116?mt=8
I know how to dynamically increase the height of a cell but that is a different effect than the above. The slide out view affect doesn't seem to increase the cell's height. Also, the new view isn't as wide. Any suggestions on how to go about designing that?
You could create and insert, with animation, a new custom cell under it. Check out insertRowsAtIndexPaths:withRowAnimation:.
UPDATE
I also really like your idea of using a "slideout" view, but I agree with TechZen that this should be added as a subview of the cell.
If you want to increase the height of the cell, you need to return the correct heights for all the cells from the delegate method tableView:heightForRowAtIndexPath:. You will need to return the same height (standard is 44) for all rows except the one with the extra view which will be increased by the height of the new view.
I don't think they're sliding a view beneath the cell view, I think they're inserting the view into the cell itself and modifying the graphics to create the illusion of an overlying view.
I don't really know how they did that, but in the last minutes I tried some experiments and... the easiest solution is definitely:
NSIndexPath *myIndexPath = [NSIndexPath indexPathForRow:[selectedCell intValue]+1 inSection:0];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:myIndexPath] withRowAnimation:UITableViewRowAnimationTop];
Insert some custom graphics (cellForRowAtIndexPath) and it looks quite the same.
Those two apps are doing things that are quite different. Tweetie is overlaying a new cell on top of an existing one, while PasteBot is creating a new one underneath, and animating the expansion of the table view. Mooch! does the same thing as PasteBot, and it's a really cool effect that I'd like to duplicate.