I'm new to xcode
and iOS
. I'm following apple tutorial, but I can't figure out a thing.
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.
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
.
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.
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.
But if I do the same thing, but trying to connect it to the ViewController.swift
it works perfectly.
Now, I'm just wondering why this happens. Can't I use control-drag
with a custom 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. Storyboard is not meant to design your 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. One exception is with the custom tableView / collectionView cell though..
For connectioning between storyboard & class
you must in the storyboard -> customClass -> chose your class
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.