关于闭包传值,不能present页面的问题 (Swift 4)

解决: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)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值