Prabhu
Prabhu

Reputation: 13345

Associate storyboard elements to outlets and actions already defined in a class

How do you associate a Storyboard element (Label, Button etc) to outlets and actions already defined in a class? I am reusing the same custom class for two of my view controllers, so for the second one, I can't use the control-drag method to create my outlets, right, as that would create different variables?

Here's my class:

class MyCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var lblName: UILabel!
    @IBOutlet weak var imgBird: UIImageView!
}

I'm using Swift 2.

Upvotes: 0

Views: 73

Answers (1)

Duncan C
Duncan C

Reputation: 131491

You can control-drag from your UI elements onto existing outlets in your source code. When you do that the view is connected to the existing outlet rather than creating a new outlet.

You can have the same outlets point to different view elements in different scenes.

(Each scene represents a template you can use to create instances of your view controller. You can have multiple templates with different layouts.)

Upvotes: 2

Related Questions