简体   繁体   English

管理多个视图和交互

[英]Managing multiple views and interactions

I have a table that contains 4 varying types of data and depending on the type of data that is selected by the user, a specific edit view is shown. 我有一个表,其中包含4种不同类型的数据,并且根据用户选择的数据类型,将显示一个特定的编辑视图。 One of these views has one edit field, a second one has 2 edit fields, a third one uses a picker, and so on. 这些视图中的一个具有一个编辑字段,第二个具有两个编辑字段,第三个具有选择器,依此类推。 What's the best way to handle these varying views without an explosion of classes and without too 'switch'ing to figure out which data I'm working with? 什么是处理这些变化的视图的最佳方法,而又又不会激增类,也不会太“切换”以找出我正在使用的数据?

One way I can think of is to have 4 different view controllers with respective views and then launch each one when the specific item is selected in the table but is there another elegant way to do this? 我能想到的一种方法是让4个不同的视图控制器具有各自的视图,然后在表中选择了特定项时启动每个视图控制器,但是还有另一种优雅的方法吗?

You can either go with the four different view controllers, or have one view controller that accepts an argument in the initialization for which content to create. 您可以使用四个不同的视图控制器,也可以使用一个视图控制器在初始化中接受要为其创建内容的参数。 The second approach seems to work better when the views are very similar (different numbers of the same controls, etc.) 当视图非常相似(相同控件的数量不同等)时,第二种方法似乎更好地工作。
For your case, some views have pickers, some have text fields... It seems that it might be best just to create a different view controller for each. 对于您的情况,有些视图有选择器,有些视图有文本字段...似乎最好为每个视图创建一个不同的视图控制器。 With this you get added flexibility down the road, even though there is slightly more code to maintain. 这样一来,即使需要维护的代码略多,您也将获得更大的灵活性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM