Created
March 29, 2018 07:20
-
-
Save kobeumut/c76513aeebe98ac433b0186cf46c3f1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Xib class | |
import UIKit | |
protocol CustomViewDelegate: class { // make this class protocol so you can create `weak` reference | |
func goToNextScene() | |
} | |
class CustomView: UIView { | |
weak var delegate: CustomViewDelegate? // make this `weak` to avoid strong reference cycle b/w view controller and its views | |
@IBAction func toSecondButton(sender: AnyObject) { | |
delegate?.goToNextScene() | |
} | |
} | |
//Storyboard class | |
import UIKit | |
class ViewController: UIViewController, CustomViewDelegate { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let myCustomView = NSBundle.mainBundle().loadNibNamed("customView", owner: self, options: nil)[0] as! CustomView | |
myCustomView.delegate = self | |
// ... do whatever else you want with this custom view, adding it to your view hierarchy | |
} | |
func goToNextScene() { | |
performSegueWithIdentifier("toSecond", sender: self) | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment