I am SUPER new to iOS development, and I have a basic app wireframe developed. I am scratching my head at this one (and to be honest, I’m not a great coder yet, but I’m trying). Basically, I have a screen where you can add multiple tabviews:
Tab View with Two Tabs
When you click choose pit photo, you can choose a photo or take a picture and that becomes the picture on the tab. Unfortunately, it changes the picture on ALL tabs.
Basically, I am trying to insert the picture into the TabItem structure so that it’s part of the tab and not all the tabs.
Here is the code I have so far—-it may be slightly in flux but I want to somehow add the image to the tab and not always take the picture I select and put it on all of the tabs:
import Foundation
import SwiftUI
struct TabItem: Identifiable {
let id = UUID()
let name: String
let image: UIImage
}
final class DynamicTabViewModel: ObservableObject {
@Published var tabItems: [TabItem] = []
@Published var tabCount = 1
@Published var image: UIImage?
func addTabItem() {
// tabItems.append(TabItem(name: " Tab (tabCount)", image: image))
// tabItems.append(TabItem(name: " Tab (tabCount)", image: "0(tabCount).square"))
tabItems.append(TabItem(name: " Tab (tabCount)", image: UIImage(named: "IMG_7878")!))
tabCount += 1
}
func removeTabItem() {
if tabItems.isEmpty{
//do nothing
}
else{
tabItems.removeLast()
tabCount -= 1
}
}
func updateTabPic() {
//update current tabs picture
//tabItems.append(TabItem(name: " Tab (tabCount)", image: UIImage))
}
}
And help, suggestions, etc. would be super appreciated. I need to be steered into the right direction. I’m thinking when I pick the image from the image picture, I need to somehow store it in the current tab Item. I just dont know how to do it in swiftUI.
bigJoeIO is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.