Mam listę nawigacyjną z wieloma sekcjami i wierszami. Wybieram wiersz foo, przechodzi do widoku, który chcę. Jednak gdy wracam do widoku głównego, nie mogę wybrać wiersza foo. Naciskam wiersz foo i nic się nie dzieje.
Stukam pasek wiersza i ten wiersz wysyła mnie do swojego widoku. Powrót do widoku głównego. Wtedy nie mogę wybrać paska wiersza, ale teraz wiersz foo działa.
Czy to błąd w SwiftUI lub zaprojektowane zachowanie? Czy muszę coś zrobić, aby zresetować widoki po ich opuszczeniu?
NavigationView {
List {
Section(header: shoppingListData.lastItemSection.sectionHeader, footer: shoppingListData.lastItemSection.sectionFooter) {
ForEach(0..<shoppingListData.lastItemSection.sectionRows.count) { index in
ShoppingItemRow(shoppingListData: self.shoppingListData,
rowItem: self.shoppingListData.lastItemSection.sectionRows[index])
}
}
}
}
Oto kolejny przypadek z tym samym problemem. Mogę tylko raz wybrać wiersz wyboru formularza. Jeśli wrócę do widoku głównego, a następnie ponownie do tego widoku, mogę ponownie wybrać selektor.
Jeśli ustawię pickerStyle na SegmentedPickerStyle (), mogę wybrać go wiele razy.
struct ShoppingItemPage: View {
@ObservedObject var shoppingListData: ShoppingListData
@ObservedObject var shoppingItem: ShoppingItems
var body: some View {
Form {
Section(header: Text("Packages")) {
HStack {
Text("Quantity (\(shoppingItem.myUnit.myName))")
TextField("Quantity (\(shoppingItem.myUnit.myName))", value: $shoppingItem.stdQty, formatter: basicFormat)
.textFieldStyle(RoundedBorderTextFieldStyle())
.keyboardType(.numbersAndPunctuation)
Toggle("Need", isOn: $shoppingItem.needed)
}
HStack {
Text("Item Name")
TextField("Item Name", text: $shoppingItem.myName, onEditingChanged: { (a) in
self.shoppingItem.modified()
}) {
self.shoppingItem.modified()
}.textFieldStyle(RoundedBorderTextFieldStyle())
}
Picker(selection: $shoppingItem.urgency, label: Text("Urgency")) {
ForEach(Ledgers.ReceiptUrgency.list(), id: \.rawValue) { urgency in
Text(urgency.description()).tag(urgency)
}
}
}
}.navigationBarTitle(Text(shoppingItem.myName))
}
}
Uruchamianie XCode w wersji 11.2.1 (11B500) i iOS 13.3 beta.
Dodanie ShoppingItemRow, aby uzyskać więcej informacji
struct ShoppingItemRow: View {
@ObservedObject var shoppingListData: ShoppingListData
@ObservedObject var rowItem: ShoppingItems
var id: UUID {
return rowItem.uuidKey
}
var body: some View {
NavigationLink(destination: ShoppingItemPage(shoppingListData: shoppingListData, shoppingItem: rowItem)) {
HStack(alignment: .center) {
VStack(alignment: .leading) {
rowName
rowDescription
rowPremiumDescription
}
Spacer()
VStack(alignment: .trailing) {
rowPrice
rowPremium
}
}.padding(3)
}.background(premiumColor)
}
var rowName: Text {
if let msp = rowItem.minStorePackage {
return Text(msp.brandName).font(.body).fontWeight(.bold)
}
// fall through
return Text(rowItem.myName).font(.body).fontWeight(.bold)
}
var rowPrice: Text {
if let msp = rowItem.minStorePackage {
let dq = msp.defQty
let pr = msp.pkgCost(pkgQty: dq)
return Text(pr.cash()).font(.body)
} else if let mp = rowItem.minPackage {
let dq = mp.defQty
let pr = mp.pkgCost(pkgQty: dq)
return Text(pr.cash()).font(.body)
} else {
return Text("rowPrice Test")
// return Text("0").hidden() as! Text
}
}
var rowPremium: Text? {
if let msp = rowItem.minStorePackage {
let dq = msp.defQty
let pc = msp.premiumCents(pkgQty: dq)
if pc == 0 {
return Text("0").hidden() as? Text
} else {
return Text(pc.cash()).font(.caption)
}
} else {
return Text("0").hidden() as? Text
}
}
var rowDescription: Text? {
if let msp = rowItem.minStorePackage {
let dq = msp.defQty
let unitText: String
if msp.pkgInteger {
if dq == 1 {
unitText = "\(msp.pkgSize.basicString()) \(rowItem.myUnit.myName)"
} else {
unitText = "\(dq.basicString()) x [\(msp.pkgSize.basicString()) \(rowItem.myUnit.myName)]"
}
} else {
unitText = "\((dq * msp.pkgSize).basicString()) \(rowItem.myUnit.myName)"
}
let thisText = "\(unitText) \(msp.costX()) (\(msp.stdPrice.cash())/\(rowItem.myUnit.myName))"
return Text(thisText).font(.caption)
} else {
return Text("").hidden() as? Text
}
}
var rowPremiumDescription: Text? {
if let msp = rowItem.minStorePackage {
let dq = msp.defQty
let premium = msp.premiumCents(pkgQty: dq)
if premium == 0 {
return Text("Minimum price at \(shoppingListData.dataStack.currentReceipt.myStore!.longName).").font(.caption)
} else {
let mp = rowItem.minPackage!
return Text("\(premium.cash()) cheaper at \(mp.myStore.longName)").font(.caption)
}
} else if let mp = rowItem.minPackage {
let dq = mp.defQty
let pc = "Minimum price \(mp.pkgCost(pkgQty: dq).cash()) (\(mp.stdPrice.cash()) \(rowItem.myUnit.myName)) at "
let storeName = mp.myStore.longName
return Text("\(pc)\(storeName)").font(.caption)
} else {
return Text("").hidden() as? Text
}
}
var premiumColor: Color {
if let msp = rowItem.minStorePackage {
let dq = msp.defQty
let pc = msp.premiumCents(pkgQty: dq)
if pc == 0 {
return Color.yellow
} else {
return Color.clear
}
} else {
return Color.clear
}
}
}
ShoppingItemRow