空白屏幕,默认的Xcode 12 Core Data项目 [英] Blank white screen with default Xcode 12 Core Data project

查看:136
本文介绍了空白屏幕,默认的Xcode 12 Core Data项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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.

预览也不会显示添加项目"在视图中应该存在的ButtonEditButton.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆