How can you reload the ViewController after rejecting the modally presented view controller in Swift?

I have a first tableViewController that opens a second tableViewcontroller after clicking on a cell. The second view controller is presented modally (Show Detail segue) and is rejected with:

self.dismissViewControllerAnimated(true, completion: {})

At this point, the second view controller slides and shows the first view controller below it. At this point, I would like to restart the first view controller. I understand that this may require the use of delegate functions, but I'm not sure how to proceed. Thanks in advance for your help!

+4
source share
2

-, .

, , , .

!

Singleton ()

protocol ModalTransitionListener {
    func popoverDismissed()
}

class ModalTransitionMediator {
    /* Singleton */
    class var instance: ModalTransitionMediator {
        struct Static {
            static let instance: ModalTransitionMediator = ModalTransitionMediator()
        }
        return Static.instance
    }

private var listener: ModalTransitionListener?

private init() {

}

func setListener(listener: ModalTransitionListener) {
    self.listener = listener
}

func sendPopoverDismissed(modelChanged: Bool) {
    listener?.popoverDismissed()
}
}

, :

class PresentingController: ModalTransitionListener {
//other code
func viewDidLoad() {
    ModalTransitionMediator.instance.setListener(self)
}
//required delegate func
func popoverDismissed() {
    self.navigationController?.dismissViewControllerAnimated(true, completion: nil)
    yourTableViev.reloadData() (if you use tableview)
}
}

, , ViewController viewDid/WillDisappear add:

ModalTransitionMediator.instance.sendPopoverDismissed(true)
+2

viewDidAppear:, , .

- , .

, TableViewController Table1VC, - Table2VC. Table2Delegate, , table2WillDismissed.

protocol Table2Delegate {
    func table2WillDismissed()
}

Table1VC .

, , Table2VC, :

weak var del: Table2Delegate?

Table1VC.

, , dismissViewControllerAnimated Table2VC.

del?.table2WillDismissed()
self.dismissViewControllerAnimated(true, completion: {})

, .

+4

All Articles