每当我在Swiftui视图中包含导航栏标题时,我的iPhone(但不是模拟器)就会崩溃。如果我拿出导航栏的标题,一切正常,但我需要标题在那里。这是我的代码:
NavigationView {
List {
ForEach(self.viewModel.tasks) { task in
TaskRow(task: task)
}
.onDelete(perform: self.viewModel.delete(indexSet:))
}
.listStyle(.grouped)
.edgesIgnoringSafeArea(.bottom)
.navigationBarTitle(Text("mainTitle")) //EXC_BAD_ACCESS crash here
}
更新
我剥离了上面的代码,并开始了一个新的项目,以确保它不是我的自定义用户界面或我的业务逻辑在做一些奇怪的事情。下面的代码在我的iPhone上产生相同的崩溃。
struct ContentView : View {
var body: some View {
NavigationView {
List {
ForEach((0...10).identified(by: \.self)) { val in
Text("test")
}
}
.listStyle(.grouped)
.edgesIgnoringSafeArea(.bottom)
.navigationBarTitle(Text("Hey"))
}
}
}
知道为什么会发生这种情况,或者怎么解决它吗?