Skip to content

Instantly share code, notes, and snippets.

@kobeumut
Created March 29, 2018 07:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobeumut/c76513aeebe98ac433b0186cf46c3f1a to your computer and use it in GitHub Desktop.
Save kobeumut/c76513aeebe98ac433b0186cf46c3f1a to your computer and use it in GitHub Desktop.
//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