The pit of the IOS UI: Do not remove UITableViewCell's Contentview

Source: Internet
Author: User

See the headline, you might think, how can someone fool to do this? Well, a programmer like me who has no experience is really possible. The background to this problem is that when you need to redraw UITableViewCell , you often encounter situations where you need to clear all subview. And we have a piece of code that can take advantage of:

Uiview+utils.m

-(void) Removeallsubviews {

For (UIView *subview in self.subviews) {

[SubView Removefromsuperview];

}

}

The right approach

The right thing to do is to add all the sub-view to the Contentview .

sometableviewcell.m

[Self.contentview Removeallsubviews];

......

[Self.contentview Addsubview:view];

The wrong approach

The wrong thing to do is to add the handle view to the view of the cell itself.

sometableviewcell.m

[Self removeallsubviews];

......

[Self addsubview:view];

In the removeallsubviews , not only remove the child view that you added, but also remove the UITableViewCell Contentview .

The consequences of the mistake

The result of the wrong approach is that the cell appears blank on IOS 7 (Beta version 7.1). All the subview are not showing up. Normal on iOS 6 and iOS 8.

The pit of the IOS UI: Do not remove UITableViewCell's Contentview

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.