用ModalViewController切换View

当程序中含有多个 view,需要在之间切换的时候,可以使用 UINavigationController,或者是 ModalViewController。

UINabigationController 是通过向导条来切换多个 view。

如果 view 的数量比较少,且显示范围为全屏的时候,用 ModalViewController 更合适(比如需要用户输入信息的view,结束后自动返回 到之前的view)。

ModalViewController 并不像 UINavigationController 是一个专门的类,使用 UIViewController 的 presentModalViewController 方法指定之后就是 ModalViewController 了。


设计时要保证:

1、发起和取消ModalView的是同一个object (一般是ModalViewController的父类)。

2、一般采用自设delegate的办法实现在同一个object中控制。

3、自设delegate即ModalViewController类定义一个protocol让父类实现,并将父类设为delegate对象。

然后ModalViewController调用delegate的方法(即协议方法)时,由父类完成。

转载于:https://my.oschina.net/dake/blog/196841

猜你喜欢

转载自blog.csdn.net/weixin_34375233/article/details/91586256
今日推荐