I'm creating an iOS app with SwiftUI. I'm using:
- Xcode Version 11.3 beta (11C24b)
- iPad Simulator running iOS 13.3
- Physical iPad running also iOS 13.3
However, the app behaves different on the two devices. For example on the physical iPad, NavigationLink
can only be used once.
It is my first iOS app. So I'm wondering how these kind of errors can be circumvented or resolved?
import SwiftUI
enum ExerciseType: String, CaseIterable, Codable, Hashable {
case vowels = "Vowels"
case special = "Special Characters"
case small = "Small Characters"
case long = "Long Vovels"
}
enum LessonType: String, CaseIterable, Codable, Hashable {
case hiragana = "Introduction to Hiragana"
case katakana = "Introduction to Katakana"
case kanji = "Introduction to Kanji"
}
struct ContentView: View {
var body: some View {
NavigationView{
Form{
Section(header: Text("Default Lesson")){
List{
ForEach(LessonType.allCases, id:.self){ lesson in
NavigationLink(destination: LessonView(), label: {Text(lesson.rawValue)})
}
}
}
}
.navigationBarTitle("iPad NavigationLink")
}.navigationViewStyle(StackNavigationViewStyle())
}
}
struct LessonView: View {
var body: some View{
Form{
List{
ForEach(ExerciseType.allCases, id:.self){ exercise in
NavigationLink(destination: Text(exercise.rawValue), label: {Text(exercise.rawValue)})
}
}
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…