【问题标题】:How I will implement delegate to pass value from a child swift class to a parent objective C class?我将如何实现委托以将值从子 swift 类传递给父目标 C 类?
【发布时间】:2019-11-07 09:47:47
【问题描述】:

我正在尝试将值从 swift 类传递给目标 C 类,但是在 swift 类中创建的委托无法从目标类中识别。

快速类:

protocol ChildViewControllerDelegate
{
 func childViewControllerResponse(parameter)
}

class ChildViewController:UIViewController
{
var delegate: ChildViewControllerDelegate?
}

目标C类:

#import "Project-Swift.h"
@interface MainViewController()<ChildViewControllerDelegate>
{

// Define Delegate Method
func childViewControllerResponse(parameter)
{
}

}

Objective C 类无法检测委托。我将如何解决这个问题或我做错了什么?

【问题讨论】:

    标签: objective-c swift delegates


    【解决方案1】:

    使用 @objc 使 ChildViewControllerDelegateObjective-C 可见,即

    @objc protocol ChildViewControllerDelegate {
        func childViewControllerResponse(parameter: String)
    }
    

    根据您的要求更改 parameter 类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-07
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 2020-07-05
      • 1970-01-01
      相关资源
      最近更新 更多