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