从ViewControlller向ConrainerView传递数据始终为零

时间:2018-07-13 10:03:40

标签: ios swift uiviewcontroller

我有CurrentYearViewController,因为我使用容器显示了多个视图。问题是我发送给ContainerViewController的值总是nil

CurrentYearViewController

//calling this function after getting response, not presenting because it is called from Segmented Control 

func refreshCurrentYearListView(dict: NSDictionary) {
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let containerViewController = mainStoryboard.instantiateViewController(withIdentifier: "containerView") as!
    ContainerViewController
    containerViewController.dataDictionary = dict
}

ContainerViewController

class ContainerViewController: UIViewController {

  @IBOutlet weak var billedValueLbl: UILabel!
  var dataDictionary: NSDictionary!

    override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.


  }

  override func viewWillAppear(_ animated: Bool) {

    if let data = dataDictionary {
        populateJSON(dict: data)
    }
  }

  func populateJSON(dict: NSDictionary) {

    let N_A: String = "N/A"
    let parser = CommonParser()

    let currentYearSalesSummaryDict: NSDictionary = parser.parse(dictionary: dict, key: "currentYearInvoiceSummary")
    if currentYearSalesSummaryDict.count > 0 {
        billedValueLbl.text = parser.parse(dictionary: currentYearSalesSummaryDict, key: "totalInvoiceAmount", exceptionString: N_A)
    }
}

0 个答案:

没有答案