简体   繁体   English

在目标c文件中有一个按钮(来自pod),并从swift继承它

[英]having a button in an objective c file (from a pod) and subclassing it from swift

So I am currently using an SDK which has a XIB file and I have connected a button to its view controller as you see in the code below. 因此,我目前正在使用包含XIB文件的SDK,并且已将按钮连接到其视图控制器,如下面的代码所示。 I have done this within the pod library itself 我已经在pod库本身中完成了此操作

- (IBAction)testButton:(UIButton *)sender {
NSLog(@"test");
}

I have then subclassed the class which I placed this method in my swift file. 然后,我将将这种方法放置在swift文件中的类作为子类。 However, I am unable to access this button from the swift file itself. 但是,我无法从swift文件本身访问此按钮。 How do I override this button's functionality from my swift file itself? 如何从swift文件本身覆盖此按钮的功能?

class MyLoginViewController: BLoginViewController {

override func viewDidLoad() {
    super.viewDidLoad()

}

//I am unable to override the button in this view controller

add this line in your BLoginViewController.h 在您的BLoginViewController.h中添加此行

- (IBAction)testButton:(UIButton *)sender;

now you can override this method in your MyLoginViewController like this 现在您可以像这样在MyLoginViewController中覆盖此方法

override func test(_ sender: UIButton!) {

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM