こんにちは。
タイトルの通りなのですが、TabBarからPostViewに移動した直後に、ImagePickerControllerfが呼び出されるようにしたいです。
現状、1番初めにPostViewに移動した時だけ、呼び出されます。
しかし、一度HomeViewに戻り、再度PostViewに切り替えると、呼び出されません。
TabBarを扱っているファイルとPostView内のコードは以下のようになっています。
毎回Viewを移動する度に呼び出されるようにするためにはどうしたら良いでしょうか。
Swift
1struct ContentView: View { 2 3 //@State var bool = true 4 5 var body: some View { 6 TabView{ 7 HomeView() 8 .tabItem { Text("Home") }.tag(1) 9 PostView() 10 .tabItem { Text("Post") }.tag(2) 11 12 // .sheet(isPresented: $bool, content: { 13 // ImagePickerView() 14 //}) 15 } 16 } 17}
Swift
1struct PostView: View { 2 3 @State var bool = true 4 5 6 var body: some View { 7 NavigationView { 8 Text("POOOOOSTTTTTTTTTTT") 9 .navigationTitle("Select Photo") 10 .navigationBarTitleDisplayMode(.inline) 11 .navigationBarItems(leading: Button(action: { 12 13 }, label: {Text("Back")}), 14 trailing: Button(action:{ 15 16 }, label: { 17 Text("Next") 18 })) 19 } 20 .sheet(isPresented: $bool, content: { 21 ImagePickerView() 22 }) 23 } 24 25} 26 27struct ImagePickerView: UIViewControllerRepresentable { 28 29 func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePickerView>) -> UIViewController { 30 31 let controller = UIImagePickerController() 32 return controller 33 } 34 35 func updateUIViewController(_ uiViewController: ImagePickerView.UIViewControllerType, context: UIViewControllerRepresentableContext<ImagePickerView>) { 36 37 } 38}
あなたの回答
tips
プレビュー