Implement Uiviewcontroller jumps in view

Source: Internet
Author: User

View is not able to uiviewcontroller Push,pop and other operations, if the jump operation, generally with agents, blocks, notifications and other implementation, how to achieve in Viewcontroller subview to achieve jump operation, In fact, just get the view where the Viewcontroller can be.

Get View location Uiviewcontroller

Uiview+uiviewcontroller.h

#import <UIKit/UIKit.h> @interface UIView (Uiviewcontroller)-(Uiviewcontroller *) Viewcontroller; @end

Uiview+uiviewcontroller.m

#import "Uiview+uiviewcontroller.h" @implementation UIView (Uiviewcontroller)-(Uiviewcontroller *) Viewcontroller {        //Through the responder chain, get view controller    Uiresponder *next = Self.nextresponder;    do {        //Determine if the responder object is a view controller type        if ([Next Iskindofclass:[uiviewcontroller class]]) {            return (Uiviewcontroller *) Next;        }        Next = Next.nextresponder;    } while (next! = nil);        return nil;} @end

Or

-(Uiviewcontroller *) Viewcontroller {    //Traverse responder chain. Return first found view controller, which would be is the view ' s view Controller.    Uiresponder *responder = self;    while ((responder = [responder Nextresponder]))        if ([responder Iskindofclass: [Uiviewcontroller class]])            Return (Uiviewcontroller *) responder;        return nil;}

  

-(uiviewcontroller*) Viewcontroller {for    (uiview* next = [self superview]; next; next = Next.superview) {        Uirespo nder* Nextresponder = [next Nextresponder];        if ([Nextresponder Iskindofclass:[uiviewcontroller class]] {            return (uiviewcontroller*) nextresponder;        }    }    return nil;}

  

  

Use:

Import #import "Uiview+uiviewcontroller.h" in Subview

-(void) viewdidselect{    webviewcontroller *VC = [[Webviewcontroller alloc] init];    Vc.weburl [email protected] "http://www.baidu.com";    [Self.viewController.navigationController PUSHVIEWCONTROLLER:VC Animated:yes];}

Implement Uiviewcontroller jumps in view

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.