我遇到了一个问题,如果我尝试添加任何其他文本,按钮或任何视图相关的东西,它会在调用中给出额外参数的错误。我还没有找到一个解决方案,或者是什么导致它,虽然我认为这可能是有很多文本框和按钮,但如前所述,我不完全确定。对不起,很长的代码,我不知道是什么导致错误,所以我认为这将是最有帮助的包括它所有
struct DicePage: View {
@State public var DiceRoll: Int = 0
@State public var Modifier: String = ""
@State public var Total: Int = 0
@State public var showingAlert = false
@State public var LastDie: String = "D20"
@State public var NumRolledDie: String = ""
@State public var RolledNumbers: [Int] = []
@State public var RolledNumbersString: [String] = []
@State public var Placeholder: Int = 0
@State private var CustomDie: String = ""
@State public var Storage: GloabalStorage = GloabalStorage()
var body: some View {
VStack {
ScrollView {
Text("The Current Value Rolled is: (RolledNumbersString.joined(separator: ", ")), with a Modifier of (String(convert(Modifier, true))) rolling (String(convert(NumRolledDie, false))) die, to get a total of (String(Total)), nYou also rolled a (LastDie).")
// Text Inputs ------------------------------------------------------------------------------
TextField("Enter Modifier...", text: $Modifier)
.textFieldStyle(RoundedBorderTextFieldStyle())
TextField("How Many Die Rolled...nMake sure this is greater then 1", text: $NumRolledDie)
.textFieldStyle(RoundedBorderTextFieldStyle())
TextField("Enter Custom Die Value...", text: $CustomDie)
.textFieldStyle(RoundedBorderTextFieldStyle())
// Text Inputs ------------------------------------------------------------------------------
// Custom Die
Button(action : {
RolledNumbers.removeAll()
RolledNumbersString.removeAll()
// New Code for the thing yaknow
if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
for _ in 0...convert(NumRolledDie, false) - 1 {
Placeholder = Int.random(in: 1...convert(CustomDie, false))
RolledNumbers.append(Placeholder)
RolledNumbersString.append(String(Placeholder))
}
Total = RolledNumbers.Total(RolledNumbers) + convert(Modifier, true)
LastDie = "D(String(convert(CustomDie, false)))"
Storage.effectNoise = true
}) {
Text(" ROLL THE DICE: D(String(convert(CustomDie, false))) ")
.background(
ZStack {
Color.purple
LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
})
.foregroundColor(.black)
.cornerRadius(21)
.padding()
}
// D100 Dice Roll
Button(action : {
RolledNumbers.removeAll()
RolledNumbersString.removeAll()
// New Code for the thing yaknow
if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
for _ in 0...convert(NumRolledDie, false) - 1 {
Placeholder = Int.random(in: 1...100)
RolledNumbers.append(Placeholder)
RolledNumbersString.append(String(Placeholder))
}
Total = RolledNumbers.Total(RolledNumbers) + convert(Modifier, true)
LastDie = "D100"
}) {
Text(" ROLL THE DICE: D100 ")
.background(
ZStack {
Color.purple
LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
})
.foregroundColor(.black)
.cornerRadius(21)
.padding()
}
// D20 Dice Roll
Button(action : {
RolledNumbers.removeAll()
RolledNumbersString.removeAll()
// New Code for the thing yaknow
if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
for _ in 0...convert(NumRolledDie, false) - 1 {
Placeholder = Int.random(in: 1...20)
RolledNumbers.append(Placeholder)
RolledNumbersString.append(String(Placeholder))
}
Total = RolledNumbers.Total(RolledNumbers) + convert(Modifier, true)
LastDie = "D20"
}) {
Text(" ROLL THE DICE: D20 ")
.background(
ZStack {
Color.purple
LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
})
.foregroundColor(.black)
.cornerRadius(21)
.padding()
}
// D12 Dice Roll
Button(action : {
RolledNumbers.removeAll()
RolledNumbersString.removeAll()
// New Code for the thing yaknow
if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
for _ in 0...convert(NumRolledDie, false) - 1 {
Placeholder = Int.random(in: 1...12)
RolledNumbers.append(Placeholder)
RolledNumbersString.append(String(Placeholder))
}
Total = RolledNumbers.Total(RolledNumbers) + convert(Modifier, true)
LastDie = "D12"
}) {
Text(" ROLL THE DICE: D12 ")
.background(
ZStack {
Color.purple
LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
})
.foregroundColor(.black)
.cornerRadius(21)
.padding()
}
// D 10 Dice Roll
Button(action : {
RolledNumbers.removeAll()
RolledNumbersString.removeAll()
// New Code for the thing yaknow
if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
for _ in 0...convert(NumRolledDie, false) - 1 {
Placeholder = Int.random(in: 1...10)
RolledNumbers.append(Placeholder)
RolledNumbersString.append(String(Placeholder))
}
Total = RolledNumbers.Total(RolledNumbers) + convert(Modifier, true)
LastDie = "D10"
}) {
Text(" ROLL THE DICE: D10 ")
.background(
ZStack {
Color.purple
LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
})
.foregroundColor(.black)
.cornerRadius(21)
.padding()
}
// D8 Dice Roll
Button(action : {
RolledNumbers.removeAll()
RolledNumbersString.removeAll()
// New Code for the thing yaknow
if (convert(NumRolledDie, false) > 80) { NumRolledDie = "80" }
for _ in 0...convert(NumRolledDie, false) - 1 {
Placeholder = Int.random(in: 1...8)
RolledNumbers.append(Placeholder)
RolledNumbersString.append(String(Placeholder))
}
Total = RolledNumbers.Total(RolledNumbers) + convert(Modifier, true)
LastDie = "D8"
}) {
Text(" ROLL THE DICE: D8 ")
.background(
ZStack {
Color.purple
LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0.3), Color.clear]), startPoint: .top, endPoint: .bottom)
})
.foregroundColor(.black)
.cornerRadius(21)
.padding()
}
}
}
}
}
SwiftUI一次只允许10个View组件。要解决这个问题,您要么必须使用Group
结构并包装一些视图组件。或者创建具有通用视图设计的单独视图文件。
组文档:https://developer.apple.com/documentation/swiftui/group