ios - 在 objective-c 文件中有一个按钮(来自 pod)并从 swift 中继承它

标签 ios objective-c swift

所以我目前正在使用一个具有 XIB 文件的 SDK,并且我已经将一个按钮连接到它的 View Controller ,如下面的代码所示。我已经在 pod 库本身中完成了此操作

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

然后我将我将此方法放入我的 swift 文件中的类子类化。但是,我无法从 swift 文件本身访问此按钮。如何从我的 swift 文件本身覆盖此按钮的功能?

class MyLoginViewController: BLoginViewController {

override func viewDidLoad() {
    super.viewDidLoad()

}

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

最佳答案

在您的 BLoginViewController.h 中添加这一行

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

现在您可以像这样在 MyLoginViewController 中覆盖此方法

override func test(_ sender: UIButton!) {

}

关于ios - 在 objective-c 文件中有一个按钮(来自 pod)并从 swift 中继承它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48180461/

相关文章:

javascript - 通过触摸事件实时检查谷歌地图中的边界变化

java - 有没有与 Android 的 Xcode clang 静态分析器相当或相似的东西?

ios - 我找不到在 UIAlertView 中按下的按钮

c++ - 从长远来看,最好的方法是什么 : C, Objective C 或 C++?

ios - 在同一 Controller 中检测 TableView 和 CollectionView 滚动

ios - 类 CKPPTSubTest 在两个框架中都实现了。将使用两者之一。哪个是未定义的

ios - 可访问性和特征的目的是什么?

ios - Swift 编译器 - Xcode 9.1 中缺少常规

ios - 使用 UINavigationController 工具栏的替代方法

ios - 什么会使UIViewController暂时变得无响应?