Viewdidload called after closing rejection of child viewcontroller

I have a main Viewcontroller and a Child Viewcontroller.

I realized that when closing Childviewcontroller, for example:

        self.dismissViewControllerAnimated(true, completion: {
            self.dismissViewControllerAnimated(true, completion: nil);
        });

it just releases the viewview child controller and I will see the mainview controller. No other code is processed

if I close the child view control with a notification to the main view manager:

                self.dismissViewControllerAnimated(true, completion: {
                    NSNotificationCenter.defaultCenter().postNotificationName("refreshtextviewer_with_bookmark", object: nil);
                    self.dismissViewControllerAnimated(true, completion: nil);

                });

then my refreshtextviewer_with_bookmark () function is called in the main view manager and the standard viewDidLoad () is also called in parallel.

Is this the usual behavior that causes viewDidLoad () in this case after the child view controller is rejected? Is there any way to prevent this?

+1
1

. .

:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        println(__FUNCTION__)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "refreshtextviewer_with_bookmark", name: "refreshtextviewer_with_bookmark", object: nil)
    }

    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }

    @IBAction func buttonTap(sender: AnyObject) {
        let vc = self.storyboard?.instantiateViewControllerWithIdentifier("childVC") as! ChildViewController
        self.presentViewController(vc, animated: true, completion: nil)
    }

    func refreshtextviewer_with_bookmark() {
        println(__FUNCTION__)
    }
}

class ChildViewController: UIViewController {

    @IBAction func exitTap(sender: AnyObject) {
        self.dismissViewControllerAnimated(true, completion: { () -> Void in
            NSNotificationCenter.defaultCenter().postNotificationName("refreshtextviewer_with_bookmark", object: nil)
        })
    }
}

FYI __FUNCTION__ .

+2

Source: https://habr.com/ru/post/1651034/


All Articles