【发布时间】:2018-09-14 20:42:29
【问题描述】:
我有两个视图,我想将数据从一个视图传递到另一个视图。第一个视图是我想要传递给下一个视图的数据的地方,我们称之为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)
}
}
故事板是这样的:
【问题讨论】:
-
你要介绍你的第二个 VC 吗?
-
对不起,我刚刚重新检查了我正在使用当前模态 segue,如果这就是你的要求
-
你没有在你的应用中使用任何 TabBar 对吗?
-
是的,我正在使用标签栏
-
所以 HomeViewController 是你的目标 VC 吗?
标签: swift storyboard segue uistoryboardsegue