Objective-C 在View中跳转页面

#import <UIKit/UIKit.h>

@interface ParentClassView : UIView
#pragma mark-获取当前view上层的Controller
-(UIViewController *)getController;

@end
#import "ParentClassView.h"
@implementation ParentClassView
#pragma mark-获取当前view上层的Controller
-(UIViewController*)getController{
    id controller = [self nextResponder];
    while (![controller isKindOfClass:[UIViewController class]]&&controller!=nil) {
        controller = [controller nextResponder];
    }
    UIViewController *mainController=(UIViewController*)controller;
    return mainController;
}

ParentClassView这个类继承成的是UIView 
假如你在这个View中添加了一个按钮这个按钮的功能就是跳转页面

方案一: 在Controller中把本身传到ParentClassView这个View中来解决跳转问题
方案二:我推荐使用的就是GitController方法

使用只需这样写就OK啦 :
            如:
            NewsController * newsController=[NewsController new];
            //跳转风格
            newsController.modalTransitionStyle=UIModalTransitionStylePartialCurl;
            //[self getController]--------得到Controller
            //模态跳转
            [[self getController] presentViewController:newsController animated:YES completion:nil];
相关文章
相关标签/搜索