[英]Cannot control-drag in xcode between cocoa touch uiview class and subview in storyboard
I'm new to xcode
and iOS
. 我是
xcode
和iOS
新手。 I'm following apple tutorial, but I can't figure out a thing. 我正在关注Apple教程,但我一无所知。
In the tutorial, when there is the need of a connection between the storyboard
and the ViewController.swift
, it's done a connection using the control-drag
from the storyboard
to the viewController.swift
, and it works like a charm. 在本教程中,当
storyboard
viewController.swift
storyboard
和ViewController.swift
之间需要建立连接时,它是通过使用control-drag
从storyboard
viewController.swift
storyboard
到viewController.swift
的连接来完成的,它的工作原理就像一个吊饰。
If I add a subview
to storyboard
, apple does the connection and the declaration by code in a custom cocoa touch class
that implements UiView Protocol
, not using the control-drag
. 如果我将一个
subview
添加到storyboard
UiView Protocol
,apple将通过实现UiView Protocol
的custom cocoa touch class
中的代码来执行连接和声明,而不使用control-drag
。
Now, given the fact that is clear to me the code writted by apple, I'm just wondering why the control-drag
doesn't work. 现在,考虑到我清楚苹果编写的代码这一事实,我只是想知道为什么
control-drag
不起作用。
I've tried to do the same thing, adding a button
via ui and then tried to control-drag
to cocoa touch class, and I cannot do this. 我试图做同样的事情,通过ui添加一个
button
,然后试图control-drag
到可可触摸类,但是我做不到。
But if I do the same thing, but trying to connect it to the ViewController.swift
it works perfectly. 但是,如果我做同样的事情,但是尝试将其连接到
ViewController.swift
它将完美地工作。
Now, I'm just wondering why this happens. 现在,我只是想知道为什么会这样。 Can't I use
control-drag
with a custom UiView
? 我不能将
control-drag
与自定义UiView
吗?
Thanks for answering. 谢谢回答。
If you want to create a custom view that will have subview of it's own, you can do so using a Xib file (pretty much like a storyboard, but for only one view instead of for a whole app workflow) and then you'll be able to make all the connection you wish. 如果您想创建一个拥有自己的子视图的自定义视图,则可以使用Xib文件(非常类似于情节提要,但仅用于一个视图,而不是用于整个应用程序工作流)来实现,能够建立您希望的所有连接。 Storyboard is not meant to design your customView.
故事板并不旨在设计您的customView。 Connection are mainly used to provide a easy/cost-effective reach from the control grasp to it's main view's subviews (IBOutlets) or to '0 line' a target action pattern.
连接主要用于从控件抓取到其主视图的子视图(IBOutlets)或“ 0行”目标操作模式提供简便/经济高效的访问。 One exception is with the custom tableView / collectionView cell though..
不过,自定义tableView / collectionView单元格是一个例外。
For connectioning between storyboard & class 用于情节提要和课程之间的连接
you must in the storyboard -> customClass -> chose your class 您必须在情节提要中-> customClass->选择您的课程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.