UI base Gets the Viewcontroller of the current screen display

Source: Internet
Author: User

1#pragma mark-Gets the viewcontroller of the current screen display2-(Uiviewcontroller *) GETCURRENTVC3{4 Uiviewcontroller *result =Nil56 UIWindow * window =[[UIApplication sharedapplication] Keywindow];7if (window.windowlevel! =Uiwindowlevelnormal)8{9 Nsarray *windows =[[UIApplication sharedapplication] windows];10For (UIWindow * TmpwinInchWindows11{12if (Tmpwin.windowlevel = =Uiwindowlevelnormal)13{+ window =Tmpwin;15Break;16}17}18}19UIView *frontview = [[Window subviews] Objectatindex:021 id nextresponder = [ Frontview Nextresponder]; 22 23 if ([ Nextresponder iskindofclass:[uiviewcontroller class24 result = Nextresponder;else26 result = Window.rootviewcontroller; 27 28 return result; 29}             

if you want to push and pop, you need to cast the return value of the calling method to the Uinavigationcontroller type
1 Uinavigationcontroller *nc = (Uinavigationcontroller *) [self GETCURRENTVC];  2 [NC Popviewcontrolleranimated:yes]; 

UI base Gets the Viewcontroller of the current screen display

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.