Swiftui [BUG] NavigationView 和 List 仅在 iPad 模拟器上不显示 [英] Swiftui [BUG] NavigationView and List not showing on iPad simulator only
问题描述
各种iPad模拟器空白页
去苹果开发者网站下载下面的教程项目:
来自 Apple SwiftUI 教程项目的示例代码:
导入 SwiftUIstruct LandmarkList:查看{var主体:一些视图{导航视图{List(landmarkData) { 地标在NavigationLink(destination: LandmarkDetail(landmark:地标)) {LandmarkRow(地标:地标)}}.navigationBarTitle(Text(地标"))}}}struct LandmarkList_Previews: PreviewProvider {静态 var 预览:一些视图 {ForEach([iPhone SE", iPhone XS Max"], id: \.self) { deviceName in地标列表().previewDevice(PreviewDevice(rawValue: deviceName)).previewDisplayName(设备名称)}}}
根据@Procrastin8 的回答,我在这里展示示例代码,你只需要添加一行代码 .navigationViewStyle(StackNavigationViewStyle()
导入 SwiftUIstruct LandmarkList:查看{var主体:一些视图{导航视图{List(landmarkData) { 地标在NavigationLink(destination: LandmarkDetail(landmark:地标)) {LandmarkRow(地标:地标)}}.navigationBarTitle(Text("Landmarks"))}.navigationViewStyle(StackNavigationViewStyle())}}struct LandmarkList_Previews: PreviewProvider {静态 var 预览:一些视图 {ForEach(["iPhone SE", "iPhone XS Max"], id: \.self) { deviceName in地标列表().previewDevice(PreviewDevice(rawValue: deviceName)).previewDisplayName(deviceName)}}}
截图
Blank page on all kinds of iPad simulator
Go to Apple developer website to download tutorials project below:
https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation
Run this on any iPad simulator, you will just get a blank page, but the code works fine on simulator of Mac/iPhone and my real iPhone device.
This is definitely a bug, and I've reported to Apple, I am posting here just want ppl like me who said this issue, pls don't waste your time on reset simulator, checking your code, restart your laptop, wait until apple to fix this.
Screenshot
Sample code from Apple SwiftUI tutorials project:
import SwiftUI
struct LandmarkList: View {
var body: some View {
NavigationView {
List(landmarkData) { landmark in
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
LandmarkRow(landmark: landmark)
}
}
.navigationBarTitle(Text("Landmarks"))
}
}
}
struct LandmarkList_Previews: PreviewProvider {
static var previews: some View {
ForEach(["iPhone SE", "iPhone XS Max"], id: \.self) { deviceName in
LandmarkList()
.previewDevice(PreviewDevice(rawValue: deviceName))
.previewDisplayName(deviceName)
}
}
}
According to answer of @Procrastin8, I am here to show the example code, you just need to add one line of code .navigationViewStyle(StackNavigationViewStyle()
import SwiftUI
struct LandmarkList: View {
var body: some View {
NavigationView {
List(landmarkData) { landmark in
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
LandmarkRow(landmark: landmark)
}
}
.navigationBarTitle(Text("Landmarks"))
}.navigationViewStyle(StackNavigationViewStyle())
}
}
struct LandmarkList_Previews: PreviewProvider {
static var previews: some View {
ForEach(["iPhone SE", "iPhone XS Max"], id: \.self) { deviceName in
LandmarkList()
.previewDevice(PreviewDevice(rawValue: deviceName))
.previewDisplayName(deviceName)
}
}
}
Screenshot
这篇关于Swiftui [BUG] NavigationView 和 List 仅在 iPad 模拟器上不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!