Created
October 23, 2024 12:41
-
-
Save takoikatakotako/43657bbf56f285769263f0eb0f3539d3 to your computer and use it in GitHub Desktop.
SwiftUIでListにButtonを設定して異なる画面に遷移する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct ContentView: View { | |
| @State var pokemon: Pokemon? | |
| var body: some View { | |
| NavigationStack { | |
| List { | |
| Button { | |
| pokemon = .snorlax | |
| } label: { | |
| Text("Snorlax") | |
| } | |
| Button { | |
| pokemon = .slowpoke | |
| } label: { | |
| Text("Slowpoke") | |
| } | |
| Button { | |
| pokemon = .eevee | |
| } label: { | |
| Text("Eevee") | |
| } | |
| } | |
| .navigationDestination(item: $pokemon) { pokemon in | |
| switch pokemon { | |
| case .snorlax: | |
| VStack { | |
| Image(.snorlax) | |
| Text("Snorlax") | |
| } | |
| case .slowpoke: | |
| Text("Slowpoke") | |
| case .eevee: | |
| Image(.eevee) | |
| } | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| enum Pokemon: Hashable { | |
| case snorlax | |
| case slowpoke | |
| case eevee | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment