Regarding the value of the closure, the problem of not being able to present the page

Solution: The page presented, passed the value through the closure, the problem that the page cannot be presented in the closure

//page A 

 

 //Page A: There is a button, click the button to return the name of the current button through the closure

   var shareAndGetClosure: ((String) -> Void)!

    @IBAction func detailVCRedEnvelopAction(_ sender: UIButton) {

        //You must dismiss first and then do other operations. If presentView writes a closure first, it cannot present the page 

        self.dismiss(animated: true, completion: nil)

        shareAndGetClosure(sender.currentTitle!)

    }


//page B

  

//Page B: present page A, when the button in A is clicked, page A disappears and another page is presented

 let vc = PutForwardVC()

        U. mark = 1

        vc.shareAndGetClosure = {(titlStr)->Void in

            print ( "Share---> \ ( titlStr )" )

            if   titlStr == "Share and claim" {

                

                let vc = ShareofBSxibVC()

                vc. titleArr = [ "Moments" , "WeChat" , "QQ" , "Weibo" ]

                vc.imageArr =  ["share1", "share2", "share3", "share4"]

                vc.modalPresentationStyle = .overCurrentContext

                vc.shareClosur = {(strr) -> Void in

                    let vc2 = PutForwardVC()

                    vc2.mark = 2

                    vc2.shareAndGetClosure = {(str)->Void in

                        print ( "Receive---> \ ( str )" )

                        

                    }

                    vc2.modalPresentationStyle = .overCurrentContext

                    self.present(vc2, animated: true, completion: nil)

                }

                self.present(vc, animated: true, completion: nil)

               

            }

            

            

        }

        

        vc.modalPresentationStyle = .overCurrentContext

        self.present(vc, animated: true, completion: nil)




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325899387&siteId=291194637