swift – 在视图控制器之间传递数据使用从导航控制器中嵌入的视图到tabbarcontroller的segue

swift – 在视图控制器之间传递数据使用从导航控制器中嵌入的视图到tabbarcontroller的segue,第1张

概述我有两个视图,我想将数据从一个视图传递到下一个视图.第一个视图是我有数据,我想传递给下一个视图让我们称之为SourceViewController.但是SourceViewController嵌入在NavigationViewController中,secondViewController允许调用它,DestinationViewController是TabViewController中的firs @H_502_4@ 我有两个视图,我想将数据从一个视图传递到下一个视图.第一个视图是我有数据,我想传递给下一个视图让我们称之为SourceVIEwController.但是SourceVIEwController嵌入在NavigationVIEwController中,secondVIEwController允许调用它,DestinationVIEwController是TabVIEwController中的firstVIEw.

我试图使用this question的答案,它无法通过导航视图,它只是跳过整个逻辑.

这是我的代码:

overrIDe func prepare(for segue: UIStoryboardSegue,sender: Any?) {    if (segue.IDentifIEr == "loginSuccessSugue") {        if let tab = self.presentingVIEwController as? UITabbarController,let nav = tab.vIEwControllers?[0] as? UINavigationController,let destinationVC = nav.vIEwControllers.first as? HomeVIEwController {             destinationVC.currentBalance = serviceBalance        }    }}

这是HomeVIEwController:

class HomeVIEwController: UIVIEwController,UItableVIEwDelegate,UItableVIEwDataSource,UICircularProgressRingDelegate{var currentBalance = 0.0 overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    circularBalance.maxValue = CGfloat(currentBalance)     print(currentBalance)   }  overrIDe func vIEwDIDAppear(_ animated: Bool) {    print(currentBalance)    circularBalance.setProgress(value: CGfloat(currentBalance),animationDuration: 3)     }}

这就是故事板的样子:

@H_502_4@解决方法 这是我的视图控制器,您可以在其中检查我是否向tabbar第一个vIEwcontroller发送5:

class VIEwController: UIVIEwController {    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        // Do any additional setup after loading the vIEw,typically from a nib.        self.performSegue(withIDentifIEr: "segueIDentifIEr",sender: self)    }    overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()        // dispose of any resources that can be recreated.    }    // MARK: - Navigation    // In a storyboard-based application,you will often want to do a little preparation before navigation    overrIDe func prepare(for segue: UIStoryboardSegue,sender: Any?) {        let barVIEwControllers = segue.destination as! UITabbarController        let destinationNv = barVIEwControllers.vIEwControllers?[0] as! UINavigationController        let destinationVIEwController = destinationNv.vIEwControllers[0] as! FirstVIEwController        destinationVIEwController.currentBalance = 5    }}

现在您可以查看我的第一个视图控制器,您可以在哪里检查我们获得的值.

class FirstVIEwController: UIVIEwController {    var currentBalance = 0    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        // Do any additional setup after loading the vIEw.        print(currentBalance)    }    overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()        // dispose of any resources that can be recreated.    }}

现在,您可以查看我的控制台和故事板:

@H_502_4@ @H_502_4@ @H_502_4@ @H_502_4@ 总结

以上是内存溢出为你收集整理的swift – 在视图控制器之间传递数据使用从导航控制器中嵌入的视图到tabbarcontroller的segue全部内容,希望文章能够帮你解决swift – 在视图控制器之间传递数据使用从导航控制器中嵌入的视图到tabbarcontroller的segue所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1008082.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存