When iOS uses SegmentController to switch tableView, reloadData will cause repeated data creation. Solution

Source: Internet
Author: User

When iOS uses SegmentController to switch tableView, reloadData will cause repeated data creation. Solution

Place the control created on the Cell in the Cell = nil judgment, so that each time you come in, you will first judge whether there is any, so that you can avoid repeated data creation, resulting in the view becoming thicker and thicker

If (cell = nil ){

Cell = [[UITableViewCellalloc] initWithStyle: UITableViewCellStyleDefaultreuseIdentifier: cellIDD];

Self. inviteLabel = [[UILabelalloc] initWithFrame: CGRectMake (10, 5, [UIScreenmainScreen]. bounds. size. width-20, 120)];

Self. inviteLabel. numberOfLines = 0;

Self. inviteLabel. text = cell_info.title;

Self. inviteLabel. textColor = LABEL_TEXTCOLOR;

Int width = 100;

Int height = 40;

Self. button = [[UIButtonalloc] initWithFrame: CGRectMake ([UIScreenmainScreen]. bounds. size. width/2-width/2,120 + 10, width, height)];

Self. button. backgroundColor = [UIColorredColor];

[Self. buttonsetBackgroundImage: [UIImageimageNamed: cell_info.cp] forState: UIControlStateNormal];

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

// Add the long-pressed gesture

UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizeralloc] initWithTarget: selfaction: @ selector (longPress :)];

[Self. inviteLabeladdGestureRecognizer: longPress];

LongPress. minimumPressDuration = 1.0;

[Cell. contentViewaddSubview: self. button];

[Cell. contentViewaddSubview: self. inviteLabel];

Cell. backgroundColor = CELL_BACK_COLOR;

}



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.