小编Sul*_*hur的帖子

如何阻止 SwiftUI 重新加载我通过 UIViewRepresentable 使用的 WKWebView 页面?

我的代码设置了从网页获取的导航栏标题,但是每次这都会导致整个 WKWebView 重新加载...该页面相当重,因此消耗了大量时间。使用按钮设置标题时的行为相同。


struct TransitScreen: View, HandlerDelegate {

    var urlRequest: URLRequest
    @State var pageTitle = "Title 1"

    var body: some View {

        VStack {

            KSWebView(urlRequest: urlRequest, delegate: self) // WKWebView using UIViewRepresentable
             
            NavigationLink("Go", destination: Text("Some Data"))
                
            Button(action: {
               pageTitle = "replaced \(Date().toSeconds())"
            }){
               Text("Change title")
            }
            
        }.navigationBarTitle(Text(pageTitle))
        .edgesIgnoringSafeArea(.top)
    }


    func process(data: String){
        pageTitle = data
    }

}

Run Code Online (Sandbox Code Playgroud)

有什么办法可以阻止这种情况发生吗?或者另一种更新 navigationBarTitle 的方法?

ios swift wkwebview swiftui uiviewrepresentable

3
推荐指数
1
解决办法
1643
查看次数

标签 统计

ios ×1

swift ×1

swiftui ×1

uiviewrepresentable ×1

wkwebview ×1