简体   繁体   English

无法控制在故事板中的可可触摸uiview类和子视图之间的xcode中拖动

[英]Cannot control-drag in xcode between cocoa touch uiview class and subview in storyboard

I'm new to xcode and iOS . 我是xcodeiOS新手。 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 storyboardViewController.swift之间需要建立连接时,它是通过使用control-dragstoryboard viewController.swift storyboardviewController.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 Protocolcustom 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. 谢谢回答。

You can only control-drag from outlet to view on xib, after creating outlet in code you will see a dot at the left side, you can drag from there to your view and outlet will work 您只能在XIB上从插座拖曳到视图上进行拖动,在代码中创建插座后,您会在左侧看到一个点,您可以从此处拖动到视图,插座将起作用

在此处输入图片说明

In the storyboard, you have to set the class name to the view controller. 在情节提要中,您必须将类名称设置为视图控制器。 在此处输入图片说明

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.

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