代码之家  ›  专栏  ›  技术社区  ›  Jad Ghadry

将@iAction链接到中的按钮。ViewController中的xib视图

  •  0
  • Jad Ghadry  · 技术社区  · 7 年前

    我创建了一个。在我的iOS应用程序中会重复出现的视图的xib文件,其中有一个UIButton。

    我已经包括在内了。我的故事板中多个UIViewController内的xib视图。我想把一个@iAction和一个@IBOutlet链接到我手机内的按钮。特定于每个UIViewController的xib视图。换句话说,我希望每个UIViewController都能够完全管理和处理位于中的UIButton。xib视图。

    3 回复  |  直到 7 年前
        1
  •  1
  •   Abizern    7 年前

    有几种方法可以做你想做的事。

        2
  •  0
  •   Jad Ghadry    7 年前

    这是迄今为止我提出的最好的解决方案。

    1. 再一次在我的内心。xib,我用一个方法创建了一个协议,我将在步骤(1)中创建的@iAction内调用该方法
    2. @iAction将在每次调用时运行协议方法,因此每次单击按钮时。
        3
  •  0
  •   Corxit Sun    6 年前

    class YourViewController:UIViewController{
        override func viewDidLoad(){
            //ListTitleView : a xib view, action button witch called theManageButton is inside it.
            let theListTitleView = ListTitleView.init(frame:CGRect.init(x: 0, y: 0, width:  self.view.frame.width, height: 100))
    
            //Add action to theManageButton
            theListTitleView.theManageButton.addTarget(self, action: #selector(yourFunction(Sender:)), for: .touchUpInside)
        }
    
        func yourFunction(Sender:UIButton){
            //...Do something here
        }
    }