在故事板中为继承的属性创建一个插座 [英] Create an outlet in storyboard to an inherited property

查看:108
本文介绍了在故事板中为继承的属性创建一个插座的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个基本的视图控制器类BasicController,它有两个子类SubclassController和AnotherSUbClassController。 BasicController控件里面有一个按钮的视图,所以应该有一个

I'd like to create a basic view controller class BasicController with two subclasses SubclassController and AnotherSUbClassController. BasicController controls view that have a button inside them, so there should be a

weak var buttonThing: UIButton? 

属性。在实际实现中,我想在接口的各个部分使用子类:我想在故事板中绘制它们,在该绘图中放置按钮,并通过插座将按钮连接到继承的buttonThing属性。但是等一下,buttonThing属性是在超类中宣布的,甚至没有出现在子类的代码中。那么如何将按钮连接到该插座?

property in it. In the actual implementation I want to use the subclasses in various parts of the interface: I want to draw them in storyboard, put buttons in that drawings, and connect the buttons to the inherited buttonThing property via an outlet. But wait, the buttonThing property was announced in the superclass and doesn't even appear in the code of the subclasses. So how do I connect the buttons to that outlet?

推荐答案

你可以 ctrl-drag UIButton 从故事板到你的 BasicController ,用于你在故事板中列出的每个子类。然后,您可以像往常一样在每个子类中使用 buttonThing

You can ctrl-drag the UIButton from your storyboard to your BasicController for each subclass you have laid out in your storyboard. You can then use the buttonThing in each subclass as usual.

请记住将子视图控制器链接到各自的视图控制器中故事板。

Remember to link your subviewcontrollers to their respective viewcontrollers in the storyboard.

这篇关于在故事板中为继承的属性创建一个插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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