美文网首页
UIView页面 与UIViewController之间的跳转

UIView页面 与UIViewController之间的跳转

作者: 春风十里湘 | 来源:发表于2016-12-07 12:21 被阅读0次

在正常的 控制器A页面 跳转到 控制器B页面 的时候,通常用的是下面的方法:

[self.navigationController pushViewController:  animated: ];

[self.navigationController popViewControllerAnimated:];

[self presentViewController:  animated:  completion: ];

[self dismissViewControllerAnimated:  completion:];

但是从UIView页面跳转到UIViewController页面之间,是没有上述方法的。鉴于此,特收集整理了以下:

流程:在一个UIViewController(AViewController)弹出一个UIView,再从UIView跳转到另一个控制器(BViewController)。

UIView跳转到UIViewController

第一种方法:

首先在UIView的声明文件中添加:(定义一个控制器属性)

@property (nonatomic,strong) UIViewController * viewcontroller;

其次,在UIView的实现文件中的Button的点击事件中

-(void)BtnClick{

BViewController * bviewcontroller = [[AViewController alloc] init];

[self. viewcontroller.navigationController pushViewController: bviewcontroller  animated:YES];

}

之后在在AViewcontroller 弹出UIVew处,写上

view.viewcontroller=self;


第二种:直接在视图上跳转。只要在视图中直接的跳转界面。说白了就是调出UIApplication的根控制器,然后也是以导航控制器的形式进行跳转。简单实用(当然是在不需要进行传值等操作的时候。)

UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;

BViewController *bviewcontroller = [[BViewController alloc]init];

[nav pushViewController:bviewcontroller animated:YES];


第三种:运用代理,块,通知的方法:

具体代码见:UIView页面跳转到UIViewController

b、代理跳转。通常我们在跳转中经常是通过你点击了某个事件或者某个操作使你进行控制器之间的跳转。那么我们可以在这个按钮事件或者操作里面写一个代理进行跳转或者传值。

c、block跳转。代码更加的简洁。只需要在视图A中进行一次声明然后在控制器B 中进行跳转代码的实现。但是需要知道的是无论是代理还是block我们都是需要视图和控制器之间存在着联系的,不然没有办法去调用代理或者block。

d、通知跳转。通知在我看来就是比代理好的一点就是不需要视图和控制器之间有必然的关联就可以调用(当然他们最大的区别是一个可以多对多传值)。

以上,是通过网上收集加上自己整理的,只为将知识整理一下,做个笔记,分享。

相关文章

网友评论

      本文标题:UIView页面 与UIViewController之间的跳转

      本文链接:https://www.haomeiwen.com/subject/hppdmttx.html