SwiftUI - memory leak in NavigationView

前端 未结 3 558
时光取名叫无心
时光取名叫无心 2021-01-05 07:35

I am trying to add a close button to the modally presented View\'s navigation bar. However, after dismiss, my view models deinit method is never called. I\'

3条回答
  •  时光说笑
    2021-01-05 08:06

    My solution is

    .navigationBarItems(
        trailing: self.filterButton
    )
    
    ..........................................
    
    var filterButton: some View {
        Button(action: {[weak viewModel] in
            viewModel?.showFilter()
        },label: {
            Image("search-filter-icon").renderingMode(.original)
        })
    }
    

提交回复
热议问题