Can't select same row twice in SwiftUI

adamek

I have a navigation list with multiple sections and rows. I select a row foo, it navigates to the view I want. However, when I go back to the root view, I can't select row foo. I tap row foo and nothing happens.

I tap row bar and that row sends me to its view. Back to the root view. Then I can't select row bar, but now row foo works.

Is this a bug in SwiftUI or designed behavior? Is there something I need to do to reset views when I leave them?

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])
            }
        }
}
}

Here is another case with the same problem. I can only select the picker row of the form once. If I go back to the root view and then back again to this view, I can select the picker again.

If I set the pickerStyle to SegmentedPickerStyle(), I can select it multiple times.

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))
    }
}

Running XCode Version 11.2.1 (11B500) and iOS 13.3 beta.

Adding ShoppingItemRow for more information

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
        }
    }

}
Thomas Vos

The bug is fixed by Apple in iOS 13.3 beta 4. Keep in mind that iOS 13.3 was in beta at the time you tested it. It was not a bug in iOS 13.2, so this is nothing to worry about anymore.

Update for iOS 13.3 release:

The bug is fixed on physical devices but is still present on emulator.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select same row twice, and make the copy immutable

From Dev

Random long, can it be twice in a row the same number

From Dev

can't readf to the same variable twice

From Dev

can't readf to the same variable twice

From Dev

Can't read the same InputStream twice

From Dev

sqlite3: how to select same row twice when there is a match?

From Dev

ROW_NUMBER() ORDER BY, can't use column within same SELECT statement

From Dev

Select row twice if it matches IF condition twice

From Java

Check for same vowel twice in a row

From Dev

Why I can't use datepicker twice in the same table?

From Dev

Why I can't reuse WebClient to make the same request twice?

From Dev

Why can't I iterate twice over the same data?

From Dev

Searching TableView can't select row

From Dev

Can´t select first row in table

From Dev

Button Click Event doesn't fire when clicking same button twice in a row

From Dev

SQL query returning same row of data twice

From Dev

jQuery Prevent Loading same image twice in a row

From Dev

Show a random mysql row, but not the same twice

From Dev

Looping through SqlDataReader returns same row twice

From Dev

DataTables with TableTools fnSelect() fires twice on row select

From Dev

Oracle select twice in the same table without duplicates

From Dev

SQL SELECT Returning the same value twice in GridView

From Dev

How to select the same column twice with different order

From Dev

SELECT or JOIN using same column twice

From Dev

SELECT or JOIN using same column twice

From Dev

SQL: Select the same column twice in one query?

From Dev

Why can't I call a mutable method (and store the result) twice in a row?

From Dev

Why can't I make 2 paths point to the same file twice in require.js?

From Dev

Can't go back to the same page twice. c# Windows Phone 8.1

Related Related

  1. 1

    Select same row twice, and make the copy immutable

  2. 2

    Random long, can it be twice in a row the same number

  3. 3

    can't readf to the same variable twice

  4. 4

    can't readf to the same variable twice

  5. 5

    Can't read the same InputStream twice

  6. 6

    sqlite3: how to select same row twice when there is a match?

  7. 7

    ROW_NUMBER() ORDER BY, can't use column within same SELECT statement

  8. 8

    Select row twice if it matches IF condition twice

  9. 9

    Check for same vowel twice in a row

  10. 10

    Why I can't use datepicker twice in the same table?

  11. 11

    Why I can't reuse WebClient to make the same request twice?

  12. 12

    Why can't I iterate twice over the same data?

  13. 13

    Searching TableView can't select row

  14. 14

    Can´t select first row in table

  15. 15

    Button Click Event doesn't fire when clicking same button twice in a row

  16. 16

    SQL query returning same row of data twice

  17. 17

    jQuery Prevent Loading same image twice in a row

  18. 18

    Show a random mysql row, but not the same twice

  19. 19

    Looping through SqlDataReader returns same row twice

  20. 20

    DataTables with TableTools fnSelect() fires twice on row select

  21. 21

    Oracle select twice in the same table without duplicates

  22. 22

    SQL SELECT Returning the same value twice in GridView

  23. 23

    How to select the same column twice with different order

  24. 24

    SELECT or JOIN using same column twice

  25. 25

    SELECT or JOIN using same column twice

  26. 26

    SQL: Select the same column twice in one query?

  27. 27

    Why can't I call a mutable method (and store the result) twice in a row?

  28. 28

    Why can't I make 2 paths point to the same file twice in require.js?

  29. 29

    Can't go back to the same page twice. c# Windows Phone 8.1

HotTag

Archive