我有一个包含多个部分和行的导航列表。我选择一行foo,它会导航到我想要的视图。但是,当我回到根视图时,无法选择foo行。我点击第foo行,没有任何反应。
我点击行栏,该行将我发送到其视图。返回到根视图。然后,我无法选择行栏,但是现在行foo起作用了。
这是SwiftUI中的错误还是设计的行为?离开视图时,我需要做些什么来重置视图吗?
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])
}
}
}
}
这是另一个有相同问题的情况。我只能选择一次表单的选择器行。如果返回到根视图,然后再次返回到该视图,则可以再次选择选择器。
如果将pickerStyle设置为SegmentedPickerStyle(),则可以多次选择它。
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))
}
}
运行XCode版本11.2.1(11B500)和iOS 13.3 beta。
添加ShoppingItemRow以获取更多信息
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
}
}
}
您能否提供一些样本数据进行查看?
—
fulvio
添加了另一个示例。
—
adamek '19
更有趣的是内部
—
-Asperi
ShoppingItemRow
它是NavigationLink的一个错误,非常容易以小样本形式复制。请参阅我的文章:forums.developer.apple.com/message/395130。请在“反馈助手”中报告此内容,以便Apple注意到。
—
Thomas Vos
我已经在反馈助手中报告了它。
—
adamek '19