Вот мой код отправной точки, который работает нормально, т. е. подробное представление отображается на iPhone.
Код: Выделить всё
import SwiftUI
struct ContentView: View {
@State private var selectedCategory: Category?
@State private var selectedRecipe: Recipe?
var body: some View {
NavigationSplitView {
List(Category.allCases, selection: $selectedCategory) { category in
NavigationLink(value: category) {
Text(category.rawValue)
}
}
} content: {
if let selectedCategory {
List(Recipe.allCases, selection: $selectedRecipe) { recipe in
NavigationLink(value: recipe) {
Text(recipe.rawValue)
}
}
} else {
Text("Nothing selected")
}
} detail: {
if let selectedRecipe {
Text(selectedRecipe.rawValue)
} else {
Text("Nothing selected")
}
}
}
}
enum Category: String, CaseIterable, Identifiable {
var id: String {
self.rawValue
}
case main
case settings
}
enum Recipe: String, CaseIterable, Identifiable {
var id: String {
self.rawValue
}
case omelet
case cereal
}
Код: Выделить всё
...
List(Recipe.allCases, selection: $selectedRecipe) { recipe in
// NavigationLink(value: recipe) {
//
// Text(recipe.rawValue)
// }
Button {
self.selectedRecipe = recipe
} label: {
Text(recipe.rawValue)
}
}
...
Код: Выделить всё
...
Button {
self.selectedRecipe = Recipe.omelet
} label: {
Text(Recipe.omelet.rawValue)
}
...
- iOS 17 или новее
- Xcode 15.3
- macOS 14.4.1 «Sonoma»
Подробнее здесь: https://stackoverflow.com/questions/784 ... es-on-ipad