StoryBoard 处理继承的视图控制器 [英] StoryBoard handling inherited view controller

查看:60
本文介绍了StoryBoard 处理继承的视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是故事板的新手.我曾经使用代码来制作我的视图.我有一个问题.

I am new to storyboard. I used to make my view using code. I have a question.

我创建了一个视图控制器

I created a view controller

@interface FunctionViewController : UIViewController

我已经用我的代码添加了

And I have use my code to add

  1. 全屏按钮(alpha:0.5)
  2. 中间的弹出式视图(非全屏)

然后我创建了另一个视图控制器

Then I created another Viewcontroller

@interface PlayFunctionViewController : FunctionViewController

并在弹出式视图上添加一些视图

and add some views on the popup-like view

我想使用故事板重新创建这些东西.

I want to recreate these stuff by using storyboard.

如何使用界面构建器和故事板构建这些我不需要在 FunctionViewController 的每个子类中布局全屏按钮和弹出式视图?

How can I build these using interface builder and storyboard so that I don't need to layout the full screen button and the popup-like view in every subclass of FunctionViewController?

推荐答案

你不能在故事板的子类中继承超类的布局,即如果你在故事板的视图控制器中直观地布置元素并连接它们要用于代码、视图控制器的子类,甚至同一类的其他实例,都必须单独布置,并且不会自动填充或更新.

You can't inherit the layout of a superclass in a subclass in a storyboard, i.e. if you visually lay out elements in a view controller in a storyboard and connect them to code, subclasses of that view controller, and even other instances of the same class, will have to be laid out individually, and will not automatically be populated or updated.

换句话说,在故事板中,您必须手动布置和连接所有界面元素在添加到故事板的每个单独实例和子类中.这为您提供了灵活性,因为您可以在整个应用中重复使用同一类的多个实例并以不同的方式对其进行布局,但您无法继承布局.

In other words, in a storyboard, you will have to manually lay out and connect all your interface elements in every individual instance and subclass that you add to the storyboard. This gives you flexibility in that you can reuse multiple instances of the same class throughout your app and lay them out differently, but it does not give you the ability to inherit layouts.

如果你想在子类中继承你的布局,在你的超类的viewDidLoad中以编程方式进行你的布局,然后你所有的子类都会有那些界面元素,即使你设计和布局它们在您的故事板中(它们在故事板中不可见,但会在您构建和运行您的应用时出现).

If you want to inherit your layout in subclasses, do your layout programmatically in the viewDidLoad of your superclass, and then all of your subclasses will have those interface elements, even if you design and lay them out in your storyboard (they will not be visible in the storyboard, but they will appear when you build and run your app).

基本上,如果您希望在一个类及其所有子类中具有相同的界面元素,请以编程方式创建它们,并且它们将存在于所有实例和子类实例中,即使您在您的故事板.

Basically, if you want to have interface elements that are the same in a class and all its subclasses, create them programmatically, and they will exist in all instances and subclass instances, even if you create and design the instances themselves in your storyboard.

您可以混合使用代码和故事板,因此您可以在故事板中创建一些元素,但其他需要在代码中出现在所有实例和子类中的元素.

You can mix code and storyboard, so you can create some elements in your storyboard, but others that need to be present in all instances and subclasses, in code.

这篇关于StoryBoard 处理继承的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆