我目前正在学习iOS小部件,当我尝试预览我的小部件时遇到了这个奇怪的错误。以下是诊断的内容:
== PREVIEW UPDATE ERROR:
PotentialCrashError: Update failed
ZohoMailWidgetTest may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application.
==================================
| RemoteHumanReadableError
|
| ArchivingError: failedToEncode(types: [SwiftUI.(unknown context at $107d0ac9c).ListRepresentable<SwiftUI.CollectionViewListDataSource<Swift.Never>, SwiftUI.SelectionManagerBox<Swift.Never>>, SwiftUI.(unknown context at $107d0ac9c).ListRepresentable<SwiftUI.CollectionViewListDataSource<Swift.Never>, SwiftUI.SelectionManagerBox<Swift.Never>>])
我的代码的相关主体如下所示:
struct MailWidgetTestWidgetEntryView : View {
var entry: Provider.Entry
var body: some View {
HStack {
VStack {
VStack {
Image(systemName: "envelope")
Text("494")
}
Image(systemName: "pencil.circle.fill")
.frame(maxHeight: .infinity, alignment: .bottom)
}
List {
MailWidgetListCellView()
MailWidgetListCellView()
MailWidgetListCellView()
}
}
}
}
struct MailWidgetListCellView: View {
var body: some View {
HStack {
VStack {
HStack {
Text("Team Spark")
.font(.subheadline)
.frame(maxWidth: .infinity, alignment: .leading)
Text("12:15 PM")
.font(.caption)
}
Text("Use Spark to reclaim your focus")
.font(.subheadline)
.frame(maxWidth: .infinity, alignment: .leading)
}
Image(systemName: "checkmark.circle.fill")
.font(.title)
.frame(maxHeight: .infinity)
}
}
}
当我将
List
更改为 VStack
时,不会弹出此错误,如下所示:
struct MailWidgetTestWidgetEntryView : View {
var entry: Provider.Entry
var body: some View {
HStack {
VStack {
VStack {
Image(systemName: "envelope")
Text("494")
}
Image(systemName: "pencil.circle.fill")
.frame(maxHeight: .infinity, alignment: .bottom)
}
VStack { //no errors now
MailWidgetListCellView()
MailWidgetListCellView()
MailWidgetListCellView()
}
}
}
}
我在其他地方找不到解决此问题的方法。有谁知道我该如何解决这个问题?
您不能在小部件中使用任何可滚动元素,因为它们不支持滚动。 WWDC 视频中提到了此行为。