objective-c - 如何从 Objective-C 类推送 Swift View Controller 并将数据传回并继续 Objective C 类中的下一个过程

标签 objective-c swift delegates closures objective-c-swift-bridge

我想从我的 Objective-C uiviewcontroller 推送 swift UIViewController 并等待该 viewcontroller 发回数据。我该怎么做。

我尝试在 swift 中使用协议(protocol)/委托(delegate),但它会抛出错误,因为即使我导入“Pass-swift.h”桥接头文件,它在 objc .h 文件中也不可用。

我很好奇我是否可以使用完成 block ,如果可以的话怎么办?或者任何其他方法?

//Parentviewcontroller.m file


- (void)sendNextbutton:(id)sender{

UIViewController *vc = [[SecurityQuestionViewController alloc] init];

[self.navigationController pushViewController:vc animated:YES];

// I want below signup  function to calll after getting data back from vc viewcontoller
[self singupWithSecurityQuestion];}

//.h文件

#import  "PassSDK-Swift.h"


@interface ParentViewController : UIViewController <MyProtocol>

@end

//SecurityQuestionViewController.swift

 @objc protocol MyProtocol {
   func setResultofSecurityQuestion(valueSent: [NSDictionary])
 }

@objc public class SecurityQuestionViewController: UIViewController
{    
  var delegate: MyProtocol?

@objc func didTapSubmitButton(sender: UIButton){
    let data: [NSDictionary] = getQuesDictionary()
    print(data)
    delegate?.setResultofSecurityQuestion(valueSent: data)
    navigationController?.popViewController(animated: true)
    dismiss(animated: true, completion: nil)
  }

}

//我应该将数据返回给ParentViewController,它应该等待快速 View Controller 发回数据,然后它应该转到下一个函数/方法-singupWithSecurityQuestion。

最佳答案

所以答案是使用

       @objc protocol MyProtocol: class {
  func setResultofSecurityQuestion(valueSent: [NSDictionary])
          }

和 @objc 无处不在

关于objective-c - 如何从 Objective-C 类推送 Swift View Controller 并将数据传回并继续 Objective C 类中的下一个过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58152157/

相关文章:

objective-c - 将 float 转换为 NSDate

objective-c - 驯服 XCode 的自动完成选项

ios - CompileSwiftSources 正常 x86_64 com.apple.xcode.tools.swift.compiler

c++ - 来自绑定(bind)方法的原始函数指针

c# - 在 IOC 容器中使用委托(delegate)和事件时避免强制依赖关系

objective-c - 使用双间接指针分配将项目转换为 ARC

iOS 9.2.1 应用程序在启动时崩溃

swift - 这个简单的 Swift 函数构建器示例有什么问题?

c# - 避免在 C# 中重复订阅事件

iphone - 设置需求显示 : Too long between redraw cycles