SHARE
TWEET

Untitled

a guest Sep 18th, 2019 149 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Custom View
  3. */
  4.  
  5. class CustomView: UIView() {
  6.  
  7.     @IBOutlet weak var actionButton: UIButton!
  8.    
  9.     public var buttonAction:  (() -> Void)?
  10.  
  11.     // init coder, frame
  12.  
  13.     private func initialize(){
  14.         //...
  15.         //=== actionButton
  16.         self.actionButton.addTarget(self, action: #selector(self.actionButtonTouch(_:)), for: .touchUpInside)
  17.     }
  18.  
  19.     @objc func actionButtonTouch(_ sender: UIButton) {
  20.         buttonAction?()
  21.     }
  22. }
  23.  
  24. /*
  25.     ViewController
  26. */
  27.    
  28.     func initContentView() {
  29.         let customView = ...
  30.  
  31.         customView.buttonAction = { [weak self] in
  32.             self?.x()
  33.             let mainViewController = MainViewController()
  34.             self?.navigationController?.pushViewController(mainViewController, animated: true)
  35.         }
  36.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top