在一个SwiftUI
应用程序中,我面临着一个新的挑战,希望有人能给我一些提示或指导。到目前为止,我所看到的在应用程序各部分之间进行通信的机制似乎不太适合这里。但这可能是由于我对SwiftUI
.
首先是相关代码:
class SceneDelegate {
... lot of code irrelevant to the question ...
func scene(_ scene: UIScene,
continue userActivity: NSUserActivity) {
... useful things happening for the app ...
// Now the view should change ... by some mechanism.
// This is the point of the question.
}
}
和:
struct ContentView: View {
... lot of code irrelevant to the question ...
var body: some View {
VStack {
... code to draw the view ...
}
... more code to draw the view ...
}
}
其次,我的问题是:如何在Scene(:continue内部执行处理后,让我的视图重绘自己?
我有一些想法,在场景中做一些事情(:继续功能会影响视图的绘制。
不幸的是,在尝试实现时,我意识到绘制视图的代码是在场景(:继续函数)之前执行的。因此我需要一些其他机制(如通知、绑定或??)来重绘视图。
有没有好的做法或标准的方法来做到这一点?