【问题标题】:NavigationLink not pulling new view into correct locationNavigationLink 没有将新视图拉到正确的位置
【发布时间】:2020-07-16 12:48:35
【问题描述】:

我有一个 NavigationLink 将表单视图拉到列表视图之上。我正在经历的是当视图被拉入时发生的这种“橡皮筋”效应。我无法用作品来解释它所以here is a gif explaining it

这是一个导航视图的sn-p

NavigationView {
    List {
        ForEach(self.tables) { table in
            NavigationLink(destination: TableStatusView(table: table)) {
                tableCellView(tableNumber: table.number, clean: table.clean, inUse: table.inUse)
            }
        }
        ...
    }
    ...
}

这是它的视图

struct TableStatusView: View {
    @Environment(\.managedObjectContext) var managedObjectContext
    @FetchRequest(fetchRequest: Table.getAllTables()) var tables: FetchedResults<Table>
    
    @State var table: Table
    
    var body: some View {
        Form {
            Section {
                Text("Table \(table.number)")
            }
            
            Section {
                Toggle(isOn: $table.inUse) {
                    Text("In Use")
                }
                
                Toggle (isOn: $table.clean) {
                    Text("Clean")
                }
            }
        }
    }
}

【问题讨论】:

    标签: ios swift xcode swiftui


    【解决方案1】:

    不确定@FetchRequest 是如何工作的,但您可能阻塞了主线程,导致动画跳转。尝试删除该代码,或将其移至 .onAppear 以查看问题是否仍然存在或消失。

    【讨论】:

    • 获取请求是针对 CoreData。不幸的是,由于本地属性上尚不提供属性包装器,因此无法移动它。它们必须放在视图之前,例如@State@ObservedObject
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-26
    • 2016-03-19
    • 2012-12-17
    • 2021-09-15
    • 2020-01-04
    • 2015-11-06
    • 1970-01-01
    相关资源
    最近更新 更多