Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.74 KB | None | 0 0
  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.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement