"iOS development" about UITableView's cell loop usage

Source: Internet
Author: User

If the cell is not used for recycling. A cell is recreated each time the data is displayed, and if the displayed data is re-displayed again, a cell is recreated, which can result in a waste of memory.


Solution: is to let the displayed cell into the cel pool, each time you need to use the time to take out, change the content display, swipe outside the screen to put this cell into the cell pool again waiting for the next display data. So the screen shows several cells, this is the cell altogether need to create this multiple +1.

For example: The screen can display a full 11 cells, then you need to create a 12 cell.

If you swipe on the screen, and then show off Lori, the cell is useless, and is stored in the cell pool, then show the shadow stream of the hero below the cell will not be created, but to take out the last cell pool cell changed the data displayed, so loop down.

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {    static NSString *id = @ "Hero";    Extracting data from the pool    uitableviewcell *cell = [TableView dequeuereusablecellwithidentifier:id];    if (cell = = nil) {        //create cell, it is useless to put in the ID pool        cell = [[UITableViewCell alloc] Initwithstyle: Uitableviewcellstylesubtitle reuseidentifier:id];    }    Hero *hero = Self.heros[indexpath.row];        Cell.textLabel.text = Hero.name;    Cell.detailTextLabel.text = Hero.intro;    Cell.imageView.image = [UIImage ImageNamed:hero.icon];        return cell;}


"iOS development" about UITableView's cell loop usage

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.