Nsenumerator usage and find Subview added to the top of view

Source: Internet
Author: User

Enumeration (Nsenumerator)

collection classes (such as: Nsarray, Nsset, Nsdictionary, and so on) can be obtained to Nsenumerator, an abstract class that does not have a public interface for creating instances, through Objectenumerator to the request enumerator, You can use the Reverseobjectenumerator method if you want to browse the collection from behind. The Nsenumerator Nextobject method iterates through each collection element and ends with the return of nil, which is used in conjunction with a while to iterate through all the items in the collection.

Example 1:

Nsenumerator *enumerator; = [array objectenumerator];
ID element;
while (element = [Enumerator nextobject]) {
    NSLog (@ "I found%@", Element);
}

Example 2:

Mbprogresshud in the source code through the enumeration found to add to the top of the view HUD.

+ (Mbprogresshud *) Hudforview: (UIView *) View {
    Nsenumerator *subviewsenum = [View.subviews reverseobjectenumerator ];
    For (UIView *subview in subviewsenum) {
        if ([Subview iskindofclass:self]) {return
            (Mbprogresshud *) Subview;
        }
    return
    nil;
}

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.