title: Call button clicked method in parent class in swift
body: <p>I have a ViewController that calls a class to build a menu. This menu draw a button with a buttonClicked method. I call this menu from many different ViewControllers so I need this menu to call a different button method depending on the ViewController it was called from. I cannot think how to program this?</p>
  
  <pre><code>class MenuController : UIViewController
  {
      override func viewDidLoad() 
      {
          super.viewDidLoad()
           var menu = Menu()
           self.view.addSubview(menu)
      }
  
      func buttonClicked(sender:UIButton)
      {
          var tag = sender.tag
          println("I want the button click method to call this method")
      }
  }
  
  class Menu:UIView
  {
      init()
      {
          var button:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
          button.frame = CGRectMake(0,0,280, 25)
          button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
          button.tag = Int(itemNo)
          menu.addSubview(button)
      }
  
      func buttonClicked(sender:UIButton)
      {
          var tag = sender.tag
          println(tag)
      }
  
  }
  </code></pre>