您的位置:首页 > 移动开发 > Objective-C

Objective-C 在View中跳转页面

2016-03-22 00:00 519 查看
摘要: 利用GitController 该方法获取所跳转的父类Controller

#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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: