Вопрос здесь В процессе изучения SwiftUI, это приложение специально только для WatchOS. Итак, я создаю представление строки, которое затем использует представление карусели. У меня есть, поэтому, если вы нажмете на элемент списка, он попросит вас ввести ваш счет. Это, конечно, входит в строку (я мог бы sh, я мог бы получить его до go для int, но у меня не сработало бы.) Оценка кадров показывает себя хорошо. Тем не менее, я пытаюсь найти способ получить общий счет, чтобы добавить правильно.
Например,
Оценка 1 кадра 5 Общая оценка 5
Оценка 2 кадра 2 Общая оценка 7
Оценка 3 кадра 10 Общая оценка 17
...
Любая помощь будет высоко ценится благодаря
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)
}
}
}