清理swift如何将数据传递回viewController

时间:2018-02-06 09:08:11

标签: swift swift3

class ListBillPaymentFavoriteRouter: NSObject, ListBillPaymentFavoriteRoutingLogic, ListBillPaymentFavoriteDataPassing {
    weak var viewController: ListBillPaymentFavoriteViewController?
    var dataStore: ListBillPaymentFavoriteDataStore?

    // MARK: Routing

    func routeToBillPaymentInput() {
        let destinationVC = BillPaymentInputViewController.instantiate()
        var destinationDS =  destinationVC.router!.dataStore!
        passDataToBillPaymentInput(source: dataStore!, destination: &destinationDS)
        navigationToBillPaymentInput(source: viewController!, destination: destinationVC)
    }

    // MARK: Navigation

    func navigationToBillPaymentInput(source: ListBillPaymentFavoriteViewController, destination: BillPaymentInputViewController) {
        source.navigationController?.pop_FromLeftMoveToRight()
    }

    // MARK: Passing data

    func passDataToBillPaymentInput(source: ListBillPaymentFavoriteDataStore, destination: inout BillPaymentInputDataStore) {
        destination.testTest = "Yessssss"
    }


}

当我弹出到navigationController时,我无法接收数据

3 个答案:

答案 0 :(得分:1)

请参阅我编写的以下项目,以熟悉Clean Swift Architecture。如果您需要任何澄清,请告诉我们!

Clean Swift Sample Program

答案 1 :(得分:0)

我们应该viewController,例如

func routeToBillPaymentInput() {
    let index = viewController!.navigationController!.viewControllers.count - 2
    let destinationVC = viewController?.navigationController?.viewControllers[index] as! BillPaymentInputViewController
    var destinationDS =  destinationVC.router!.dataStore!
    passDataToBillPaymentInput(source: dataStore!, destination: &destinationDS)
    navigationToBillPaymentInput(source: viewController!, destination: destinationVC)
}

答案 2 :(得分:0)

完全

class ListBillPaymentFavoriteRouter: NSObject, ListBillPaymentFavoriteRoutingLogic, ListBillPaymentFavoriteDataPassing {
weak var viewController: ListBillPaymentFavoriteViewController?
var dataStore: ListBillPaymentFavoriteDataStore?

// MARK: Routing

func routeToBillPaymentInput() {
    let index = viewController!.navigationController!.viewControllers.count - 2
    let destinationVC = viewController?.navigationController?.viewControllers[index] as! BillPaymentInputViewController
    var destinationDS =  destinationVC.router!.dataStore!
    passDataToBillPaymentInput(source: dataStore!, destination: &destinationDS)
    navigationToBillPaymentInput(source: viewController!, destination: destinationVC)
}

// MARK: Navigation

func navigationToBillPaymentInput(source: ListBillPaymentFavoriteViewController, destination: BillPaymentInputViewController) {
    source.navigationController?.popViewController(animated: true)
}

// MARK: Passing data

func passDataToBillPaymentInput(source: ListBillPaymentFavoriteDataStore, destination: inout BillPaymentInputDataStore) {
    destination.testTest = "Yessssss"

}

}