空白屏幕,默认的Xcode 12 Core Data项目 [英] Blank white screen with default Xcode 12 Core Data project
问题描述
在Xcode 12.1.1,Mac OS X Catalina 10.15.17上启动带有Core Data的全新即用SwiftUI项目时,无论是在模拟器上还是在我的计算机上,该项目都会构建为白屏设备.
When starting a brand new out-of-the-box SwiftUI project with Core Data on Xcode 12.1.1, Mac OS X Catalina 10.15.17, the project just builds to a white screen - whether on the simulator or on my device.
预览也不会显示添加项目"在视图中应该存在的Button
或EditButton
.
The Preview also does not show the "Add Item" Button
or EditButton
that are supposed to be there in the view.
我真的不知道为什么,想知道是否有人对此有解决方案?有很多关于Xcode较旧版本的报告,这些报告当然与Xcode 12不相关.
I have literally no idea why, and wonder if anyone has a solution to this? There are reports of this for much older versions of Xcode which are of course not relevant to Xcode 12.
推荐答案
它需要添加更多代码-包装为NavigationView
并为按钮放置单独的位置(当然,您可以根据需要进行修改)
It needs to add some more code - wrap into NavigationView
and separate placements for buttons (which you can modify to your needs, of course)
使用Xcode 12.1/iOS 14.1编写的演示
Demo prepared with Xcode 12.1 / iOS 14.1
var body: some View {
NavigationView {
List {
ForEach(items) { item in
Text("Item at \(item.timestamp!, formatter: itemFormatter)")
}
.onDelete(perform: deleteItems)
}
.toolbar {
#if os(iOS)
ToolbarItem {
EditButton()
}
#endif
ToolbarItem(placement: .bottomBar) {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
}
}
这篇关于空白屏幕,默认的Xcode 12 Core Data项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!