IOS: How to get a view controller instance

Source: Internet
Author: User

To get a view controller instance, you can use its exposed member variable value instead of re-opening a piece of memory, and the original instance does not just want a piece of memory area
instance Method
-(Rootviewcontroller *) <span style= "font-family:arial, Helvetica, Sans-serif;" >rootviewcontroller</span>{    Uiresponder *next = self.nextresponder;    Do {        if ([Next Iskindofclass:[rootviewcontroller class]]) {            return (Rootviewcontroller *) next;        }        Next = Next.nextresponder;    } while (next! = nil);    return nil;}
class Method
+ (Rootviewcontroller *) <span style= "font-family:arial, Helvetica, Sans-serif;" >rootv</span><span style= "font-family:arial, Helvetica, Sans-serif;" >iewcontrollerwithview: (UIView *) view</span>{    uiresponder *next = view.nextresponder;    Do {        if ([Next Iskindofclass:[rootviewcontroller class]]) {            return (Rootviewcontroller *) next;        }        Next = Next.nextresponder;    } while (next! = nil);    return nil;}

I personally feel that the class method used better, he only write in the instance you need to get the class call can be, view is usually your current view, and only write once, to a certain extent reduce the demo volume



IOS: How to get a view controller instance

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.