在 AddViewController 和 DetailViewController 之间共享代码
在基本上显示相同信息的两个视图控制器之间共享代码的最佳方法是什么?我的addView 与我的detailView 非常相似。我尝试过对它们两个使用一个视图控制器,但这似乎变得很混乱,而且我也无法遵循这些信息。
因此,如果我决定使用两个视图控制器,仅复制和粘贴然后更改一些代码是“最佳”还是“最有效”?我认为这会起作用,但可能不是最好的,因为如果我稍后更改其中的代码,那么我可能也必须在另一个中更改它。并不可怕,但它似乎不是最有效的解决方案。
What would be the best way to share code between two view controllers that basically show the same information? My addView is very similar to my detailView. I've tried using one view controller for the both of them, but that seemed to get messy and I was not able to follow the information as well.
So if I decide to use two view controllers, is it "best" or "most efficient" to just copy and paste and then change some code? I'm thinking that would work but it might not be best because if I change code in one later on, then I'd probably have to change it in the other one as well. Not terrible but it doesn't seem like the most efficient solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用继承来解决这个问题。如果视图 B 与视图 A 非常相似,则使视图 B 继承自视图 A。
下面是如何在类中使用继承的示例。
继承 - Techotopia
You could solve this problem using inheritance. If View B is very similar to View A then make View B inherit from View A.
Here is an example of how to use inheritance in your class.
Inheritance - Techotopia