Posts

Post not yet marked as solved
4 Replies
2.1k Views
Hi,Is anyone else seeing issues with reusable cells in iOS 13 only?I have an app that has several custom cells dequeued in cellForRowAt function. Each cell dequeued is selected based on the datasource and works correctly in previous versions of iOS. I am aware of how reuse works and reset/assign all values to each cell type as it is created.There are no repeated values when scrollling the exact same data on same devices running iOS 11 or 12, but iOS13 is showing reused cells with data that isn't in the data source as though I have not reset it correctly.Does anyone of any changes in iOS13 that would cause this behaviour? Any help would be appreciated.---------This is the code from my function. The POSNEGLR cell has a name label and 2 segmented controls on the cell that are set based on results in the data source.The datasource entry retreived into testToShow defines which cell type to use (ie testToShow["Cell"] is the cell identifier that tells me which custom cell to use. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { //get the Group key from the title of the section, and then find the appropriate array entry for this group let testToShow = getTestDetailsForIndexPath(indexPath:indexPath) if testToShow["Cell"] == "POSNEGLR" { let cell = tableView.dequeueReusableCell(withIdentifier: "POSNEGLR", for: indexPath) as! TestPositiveNegativeCellLR let testName = testToShow["Name"] cell.testName.text = testName //this has been. added to explicitly reset the values of all segments to -1 in case we don't find any (but code below also sets it) cell.testPosNegLeft.selectedSegmentIndex = -1 cell.testPosNegRight.selectedSegmentIndex = -1 //Set values for the segmented controls based on any results already recorded for this test //Check if we have an array entry that has a key with the testName in it, and look for results recorded let resultLeft = filterTestResultsForSearchText(testName: testName!, searchText: "L -") print("Result left is \(String(describing: resultLeft)) for testName \(String(describing: testName))") if resultLeft != nil { if (resultLeft?.contains("NEG"))! { cell.testPosNegLeft.selectedSegmentIndex = 0 } else if (resultLeft?.contains("POS"))! { cell.testPosNegLeft.selectedSegmentIndex = 1 } else { cell.testPosNegLeft.selectedSegmentIndex = -1 } } else {. //no result for this test - make the segment unselected cell.testPosNegLeft.selectedSegmentIndex = -1 } //Get the result for second segmented control let resultRight = filterTestResultsForSearchText(testName: testName!, searchText: "R -") print("Result right is \(String(describing: resultRight)) for testName \(String(describing: testName))") if resultRight != nil { if (resultRight?.contains("NEG"))! { cell.testPosNegRight.selectedSegmentIndex = 0 } else if (resultRight?.contains("POS"))! { cell.testPosNegRight.selectedSegmentIndex = 1 } else { cell.testPosNegRight.selectedSegmentIndex = -1 } } else { cell.testPosNegRight.selectedSegmentIndex = -1 } return cell } else if testToShow["Cell"] == "POSNEG" { let cell = tableView.dequeueReusableCell(withIdentifier: "POSNEG", for: indexPath) as! TestPositiveNegativeCell let testName = testToShow["Name"] cell.testName.text = testName //GET TEST RESULTS FOR THIS TEST IF EXIST AND CHECK RESULT TO MATCH SEGMENT let testResults = filterTestResultsForMatchingResults(testName:testName!) if testResults != nil { if (testResults?.contains("NEG"))! { cell.testPosNeg.selectedSegmentIndex = 0 } else if (testResults?.contains("POS"))! { cell.testPosNeg.selectedSegmentIndex = 1 } else { cell.testPosNeg.selectedSegmentIndex = -1 } } else { cell.testPosNeg.selectedSegmentIndex = -1 } return cell } else if testToShow["Cell"] == "None" { let cell = tableView.dequeueReusableCell(withIdentifier: "None", for: indexPath) cell.textLabel?.text = testToShow["Name"] return cell } else { let cell = tableView.dequeueReusableCell(withIdentifier: "None", for: indexPath) cell.textLabel?.text = "No tests to show" return cell }There are other cell types (with similar logic to first two examples shown above) in between the last two fallback cases that point to a cell with identifier "None" in the storyboard. None is just a Basic cell type (name only). When I debug this and scroll the list of tests, there are cells/tests that have results showing with result = nil in the logs. These cells then go ahead. and set the segmentedControl to -1 as per the code, but the coresponding entries show incorrectly in the app with selected segments. The exact same data does NOT do this in iOS11 and iOS12 no matter how much I scroll. Does anyone have any ideas on why this would be occuring even though I am resetting the segments to unselected each time after they are dequeued? Any help/suggestions would be much appreciated.
Posted Last updated
.