关于闭包传值,不能present页面的问题

解决:present出的页面,通过闭包传值,在闭包中不能present页面的问题

//页面A 

 

 //页面A: 有一个按钮,点击按钮通过闭包传回当前按钮的名称

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

    @IBAction func detailVCRedEnvelopAction(_ sender: UIButton) {

        //必须先dismiss后做其他操作,presentView如果先写闭包,则不能present出页面 

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

        shareAndGetClosure(sender.currentTitle!)

    }


//页面B

  

//页面B: present出页面A,当点击A中按钮时候,页面A消失,并present出另一个页面

 let vc = PutForwardVC()

        vc.mark = 1

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

            print("分享--->\(titlStr)")

            if  titlStr == "分享领取"{

                

                let vc = ShareofBSxibVC()

                vc.titleArr = ["朋友圈", "微信", "QQ", "微博"]

                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("领取--->\(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)




猜你喜欢

转载自blog.csdn.net/flyingfirefish/article/details/80228340