Question here In the process of learning SwiftUI, this app is specifically just for WatchOS. So I'm creating a row view that then uses a carousel view. I have it so if you click on the list item it asks you to input your score. That, of course, goes into a string (I wish I could get it to go to an int, but wouldn't work for me.) The frame score shows up fine. However, I'm trying to figure out a way to get the total score to add correctly.
For Example,
Frame 1 score 5 Total score 5
Frame 2 score 2 Total score 7
Frame 3 score 10 Total Score 17
...
Any help would be much appreciated thanks
struct StartBowlingView: View {
var body: some View {
List{
RowView(title: "1", framescore: "0", totalscore: "0")
RowView(title: "2", framescore: "0", totalscore: "0")
RowView(title: "3", framescore: "0", totalscore: "0")
RowView(title: "4", framescore: "0", totalscore: "0")
RowView(title: "5", framescore: "0", totalscore: "0")
RowView(title: "6", framescore: "0", totalscore: "0")
RowView(title: "7", framescore: "0", totalscore: "0")
RowView(title: "8", framescore: "0", totalscore: "0")
RowView(title: "9", framescore: "0", totalscore: "0")
RowView(title: "10", framescore: "0", totalscore: "0")
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
.navigationBarTitle("Frame")
.listStyle(CarouselListStyle())
}
}
struct RowView: View {
@State var title: String
@State var framescore: String
@State var totalscore: String
var TotalScore: Int {
let Totalframescore = Int(framescore) ?? 0
return Totalframescore
}
var body: some View {
NavigationLink(destination: TextField("Enter your Frame Score", text: $framescore) .border(Color.black))
{ //Start Frame List Design View
VStack(alignment: .leading) {
HStack(alignment: .center) {
Text(title)
.font(.system(.headline, design: .rounded))
.foregroundColor(Color.blue)
.multilineTextAlignment(.leading)
Divider()
Spacer()
Text("\(framescore)")
.font(.system(.body, design: .rounded))
.multilineTextAlignment(.leading)
Divider()
Spacer()
Text("\(TotalScore)")
.font(.system(.headline, design: .rounded))
.foregroundColor(Color.green)
.multilineTextAlignment(.trailing)
}
}
.listRowBackground(Color.blue)
.frame(height: 60, alignment: .topTrailing)
}
}
}