When iOS uses Segmentcontroller to switch TableView, Reloaddata creates a solution for data duplication.

Source: Internet
Author: User

The controls created on the cell are placed in the judgment of the cell==nil, so that each time you come in, you will be able to avoid duplicate data creation, resulting in a more thick view.

if (cell==Nil) {

cell=[[uitableviewcellalloc]initwithstyle:uitableviewcellstyledef Aultreuseidentifier: Cellidd];

            Self.Invitelabel=[[UILabelAlloc]initWithFrame:CGRectMake(Ten,5,[UIScreenMainscreen].bounds.size.width- -, -)];

Self. Invitelabel. numberoflines=0;

Self. Invitelabel. text=cell_info. title;

Self. Invitelabel. textcolor=Label_textcolor;

int width=;

int height=;

Self. button=[[UIButtonalloc]initwithframe:cgrectmake([UIScreen Mainscreen]. bounds. size. width/2-width/2,+ +, width, height)];

            self button Backgroundcolor=[ uicolor redcolor ";

[self. Button setbackgroundimage: [UIImageimagenamed: Cell_info. CP ]forstate:uicontrolstatenormal];

NSLog (@ "cell_info.cp:%@", Cell_info. CP);

// Add long press gesture

uilongpressgesturerecognizer *longpress=[[uilongpressgesturerecognizeralloc]initwithtarget:selfAction:@ Selector(longpress:)];

[Self. Invitelabel addgesturerecognizer: longpress];

Longpress. minimumpressduration=1.0;

[Cell. Contentview addsubview:self. Button];

[Cell. Contentview addsubview:self. Invitelabel];

Cell. backgroundcolor=Cell_back_color;

}



When iOS uses Segmentcontroller to switch TableView, Reloaddata creates a solution for data duplication.

Related Article

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.