在 swift 中导航到 popViewController 时无法将委托值添加到 JSON 参数

问题描述

我有两个视图控制器,称为 SearchVC 和 filterVC,用于两个视图控制器我有一个 JSON API....这里如果参数为零那么我需要显示总响应..像这样我可以做..

如果我使用 popviewcontroller 委托获取从 filterVC 到 SearchVC 的参数值,那么我需要在参数中显示该值..这是我无法做到的

在这里,我创建并添加了要在 filterVC 中委托的值:

 struct DataEnteredModelSave {
  var categooryName: String
  var location: String
  var budgetType: String

 }

protocol DataEnteredDelegate: class {
func userDidEnterinformation(info: DataEnteredModelSave)
}
class FilterVC: UIViewController {

weak var delegate: DataEnteredDelegate? = nil

@IBAction func applyBtn(_ sender: Any) {
    if searchServcTf.text != nil{
        let enteredData = DataEnteredModelSave(categooryName: searchServcTf.text ?? "",location: "",budgetType: "")
        delegate?.userDidEnterinformation(info: enteredData)
    }
    else if locationTf.text != nil{
        let enteredData = DataEnteredModelSave(categooryName: "",location: locationTf.text ?? "",budgetType: "")
        delegate?.userDidEnterinformation(info: enteredData)
    }
    else if searchServcTf.text != nil && locationTf.text != nil{
        let enteredData = DataEnteredModelSave(categooryName: searchServcTf.text ?? "",budgetType: "")
        delegate?.userDidEnterinformation(info: enteredData)
    }
    else{
        let enteredData = DataEnteredModelSave(categooryName: "",budgetType: "")
        delegate?.userDidEnterinformation(info: enteredData)
    }
    self.navigationController?.popViewController(animated: true)
}

在 SearchVC 中,我将委托值添加到如下参数中:这里 postServiceCalll 在我从 FilterVc 执行 popViewcontroller 时不调用

 class SearchVC: UIViewController,DataEnteredDelegate {

var serviceNmae: String? = ""
var location: String? = ""
var budgetType: String? = ""

@IBAction func filterBtn(_ sender: Any) {
    let vc = Helper.getVcObject(vcName: .SearchFilterVC,StoryBoardName: .Main) as! SearchFilterVC
    vc.delegate = self
    self.checkAndPushPop(vc,navigationController: self.navigationController)
}

func userDidEnterinformation(info: DataEnteredModelSave) {
    print("filter viewcontroller data \(info)")
    self.serviceNmae = info.categooryName
    self.location = info.location
    self.budgetType = info.budgetType
}
func postServiceCalll(){
    
          
    print("serviceName \(serviceNmae) and budgetType \(budgetType)")
    
    let param = ["location" : location,"lat": "","lng" : "","nearby": "","gender": "","budget": budgetType,"from_date": "","to_date": "","min_rate": "","max_rate": "","category_select": serviceNmae]

            
    APIReqeustManager.sharedInstance.serviceCall(param: param,method: .post,loaderNeed: true,loadingButton: nil,needViewHideShowAfterLoading: nil,vc: self,url: CommonUrl.search_service_request,isTokenNeeded: true,isErrorAlertNeeded: true,isSuccessAlertNeeded: false,actionErrorOrSuccess: nil,fromLoginPageCallBack: nil){ [weak self] (resp) in
    self?.searchServReq = SearchServiceReqBaseModel(dictionary: resp.dict as NSDictionary? ?? NSDictionary())
        dispatchQueue.main.async {
            self?.tableView.reloadData()
        }
       
    }
}
 }

现在我在 filter viewcontroller data DataEnteredModelSave(categooryName: "Adventure",budgetType: "") 中获得价值

但是在 postServiceCalll 中没有调用并且 print("serviceName \(serviceNmae) and budgetType \(budgetType)") 值没有出现..为什么我错了..请帮忙

解决方法

打电话

func userDidEnterInformation(info: DataEnteredModelSave) {
   print("filter viewcontroller data \(info)")
   self.serviceNmae = info.categooryName
   self.location = info.location
   self.budgetType = info.budgetType
   postServiceCalll() //////    << here 
}