[英]Best Techniques to share data between Landscape and portrait view controller for different device orientations
We would like to use two view controllers one for portrait(tableview) and another for landscape(mapview). 我们想使用两个视图控制器,一个用于纵向(tableview),另一个用于横向(mapview)。
We can use protocol/delegate technique to share data between different orientations. 我们可以使用协议/代理技术在不同方向之间共享数据。 The same data will be displayed in tableview or map view based on device orientation
相同的数据将根据设备方向显示在表格视图或地图视图中
Kindly suggest different techniques to share data between view controllers for orientation changes. 请提出不同的技术以在视图控制器之间共享数据以进行方向更改。
You should separate model from view. 您应该将模型与视图分开。 I would also suggest to have a base
ViewController
with interface to deal with data (it could also have the common properties/ivars
). 我还建议使用一个带有接口的基本
ViewController
来处理数据(它也可以具有公共properties/ivars
)。 In that base view controller you could handle with modifying/retrieving data. 在该基本视图控制器中,您可以处理修改/检索数据。 From that base controller the other two will inherit part of implementation as well as the interface.
其他两个将从该基本控制器继承实现的一部分以及接口。 This would help you avoid with code duplication and you could provide a nice interface (even defined by your own protocol).
这将帮助您避免代码重复,并且可以提供一个不错的接口(甚至由您自己的协议定义)。 Further changes will be easier to adopt :)
进一步的更改将更易于采用:)
Use a separate Controller-- a ViewController class or an NSObject class that can act as a main Controller for the two ViewControllers. 使用单独的Controller-一个可以充当两个ViewController的主Controller的ViewController类或NSObject类。 Also, you can create a Model class to represent data as well.
同样,您也可以创建一个Model类来表示数据。
The Main Controller provides the other two controllers with this modal object 主控制器为其他两个控制器提供此模式对象
In my opinion, for your scenario, you should keep your dataModel class separate and use Singleton pattern. 我认为,对于您的情况,应该将dataModel类保持独立,并使用Singleton模式。 Same dataModel object should be used for both ViewControllers.
两个ViewController应使用相同的dataModel对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.