6. iOS Quick Enumeration

Source: Internet
Author: User

Today, when you write a program, you want to release some of the sub-views of add on the current view when the current view jumps. Because some of the child views of add are added in other classes, the current page does not know what types of sub-views you currently have. In this way, I thought of looping through the history to see whether the current view has a sub-view of the qualifying, if any, release.

That's what I wrote:

For (UIView * SubView in Self.view.subviews) {

if ([SubView Iskindofclass:[xyzseniorqueryview class]]) {

[SubView Removefromsuperview]; SubView = nil;//Error

}

}

Error message: Fast enumeration variables can ' t is modified in ARC by default;declare the variable __strong

That is, the fast enumeration variable cannot modify its Reference property by default under Arc, declaring that the variable is __strong allowed.

Follow the prompts to modify the above statement:

for (__strong UIView * SubView in Self.view.subviews)

Or

for (UIView __strong * SubView in Self.view.subviews)

This will work as expected.

In addition, OC has a specialized fast enumeration iterator class Nsenumerator,

This class is used in the following way://Get a corresponding enumerator object

Nsenumerator * Enumerator = [self.view.subviews reverseobjectenumerator];

for (UIView * views = [Enumerator nextobject];;) Traverse

if ([Views Iskindofclass:[xyzseniorqueryview class]]) {

[Views Removefromsuperview]; views = nil;

}

}

6. iOS Quick Enumeration

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.