本文介绍了iOS:在一个ViewController中映射和列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把两个不同的视图(列表和地图)放在一个View Controller中。用户将能够通过按顶部右边的按钮来更改视图。对于这两个都将有搜索选项。如果可能,我想分开列表和地图的类。

I would like to put two different views( list and map) into one View Controller. User will be able to change view by pressing the right button on the top. For both there will be search option. If this possible, I want to separate classes for list and map.

我会gratefull的一些提示如何使它。

I would be gratefull for some tip how to make it.

推荐答案

我建议您创建一个子类 UIViewController ,此类的目的是处理数据源中的搜索栏功能和任何常见的委托回调。

I would suggest you create a parent class that is a subclass of UIViewController, the purpose of this class will be to handle the search bar functionality and any common delegate callbacks from your datasource.

从理论的角度来看,这个类将作为一个抽象类,这意味着它应该只是被子类化,而不是直接初始化,但是由于这不可能实现目标-c不要太担心。

From a theory perspective this class will act as an abstract class, meaning it should only ever be subclassed rather than directly initialised, but as this is not possible to enforce in objective-c don't worry too much about that.

下一部分取决于您是否要使用两个视图控制器进行列表和映射(如最后一节)你所说的你想要使用两个类的问题?)

This next part depends on whether you'd like to use two view controllers for list and map (as at the end of the question you said you wanted to use two classes...?)

然后你可以创建两个 UIViewControllers ,一个用于地图,一个用于列表,它们都将子类化上述抽象类。这将允许他们继承数据源委托回调和搜索栏功能。

You can then either create two UIViewControllers, one for map and one for list, and they both will subclass the above mentioned abstract class. This will allow them to inherit the datasource delegate callbacks and search bar functionality.

或者您可以将两者组合成一个 UIViewController ,它将上述抽象类和 A'sa Dickens 回答,您可以在单个xib文件中管理两个视图,并通过隐藏和显示,或从他们的超级视图添加和删除它们之间交换。

Or you can combine the two into one UIViewController that subclasses the above mentioned abstract class and as in A'sa Dickens answer, you can manage two views in a single xib file and swap between them by hiding and showing, or adding and removing them from their superview.

希望这有帮助。

这篇关于iOS:在一个ViewController中映射和列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 03:13