如何从 objective-c class 推送 swift 视图控制器并将数据传回并继续 objective c class 中的下一个过程
how to push a swift view controller from objective-c class and pass data back and continue the next process in objective c class
我想从我的 objective C uiviewcontroller 推送 swift UIViewController 并等待 viewcontroller 发送回数据。我该怎么做。
我尝试在 swift 中使用 protocol/Delegate 但它会抛出错误,因为它在 objc .h 文件中不可用,即使我正在导入 "Pass-swift.h" 桥接头文件。
我很好奇我是否可以使用完成块,如果可以,那么怎么做?或任何其他方法?
//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,它应该等待 swift 视图控制器发回数据,然后它应该转到下一个 function/method - singupWithSecurityQuestion。
所以答案是使用
@objc protocol MyProtocol: class {
func setResultofSecurityQuestion(valueSent: [NSDictionary])
}
到处都是@objc
我想从我的 objective C uiviewcontroller 推送 swift UIViewController 并等待 viewcontroller 发送回数据。我该怎么做。
我尝试在 swift 中使用 protocol/Delegate 但它会抛出错误,因为它在 objc .h 文件中不可用,即使我正在导入 "Pass-swift.h" 桥接头文件。
我很好奇我是否可以使用完成块,如果可以,那么怎么做?或任何其他方法?
//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,它应该等待 swift 视图控制器发回数据,然后它应该转到下一个 function/method - singupWithSecurityQuestion。
所以答案是使用
@objc protocol MyProtocol: class {
func setResultofSecurityQuestion(valueSent: [NSDictionary])
}
到处都是@objc