我想从我的 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/