TableView change cell height with animation effect

Source: Internet
Author: User

The effect we want is probably the following:

When we choose a cell, we are going to change its height and animate it.

How do we achieve this effect? We mainly need to use the following two methods:

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath

Two methods control the height of the cell and what happens when the cell is selected.

In our first approach, we need to implement some of the heights we want:

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath {if (the Indexpath is selected) { return 60 * 2.0;} return 60;}

In the second method, we control what we want to happen when the cell is clicked, and the "Big star code" we want to explore today is in it ~ ~

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath {[TableView Deselectrowatindexpath:indexpath animated:true];//Gets the current Indexpath and determines if the corresponding cell is selected            //The most magical place!! [TableView beginupdates]; [TableView endupdates];}

So why is there something magical happening here?

Let's focus on this line of code: [TableView beginupdates];

This line of code is interpreted in the documentation to allow TableView to insert, delete, or reload the cell

See here everyone should be suddenly understood, right? It turns out that when we click on a cell we reload our tableView again, but it's a completely different style from [TableView Reloadata], Reloaddata This method will allow the TableView to reload as a whole. The equivalent is the action on the TableView, and the beginupdates is just acting on the cell!

Well, you should already see the effect, if you still want to be able to read all our code, can be obtained by the following link ~ ~

Http://www.locassa.com/wp-content/uploads/2011/05/AnimatedTableViewCell.zip

TableView change cell height with animation effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.