我有一个包含多个部分和行的导航列表。我选择一行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
}
}
}
答案 0 :(得分:2)
我有同样的问题,请参见此post。仅在9.7英寸的物理iPad上会出现此问题。不能在模拟器中使用,也不能在我的iPhone中使用。
答案 1 :(得分:1)
该错误已由Apple在iOS 13.3 beta 4中修复。请记住,在您进行测试时,iOS 13.3处于beta版。这不是iOS 13.2中的错误,因此不再需要担心。