Mac Catalyst: UITableView Suddenly Randomly Selecting Rows After Deleting Row Via Swipe Action After a Bit of A Delay

I'm getting some new behavior I haven't seen before (on Venture 13.2.1) on UITableView.

Steps to reproduce:

  1. A table view row is selected and I swipe to delete the selected row.
  2. After about a half of a second the table view selects another row.

I'm not programmatically making a selection here after the swipe to delete. UIKit is doing it.

I set a breakpoint in -tableView:didSelectRowAtIndexPath: and it is related to the focus system:

#1 0x00000001b350b140 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:isCellMultiSelect:deselectPrevious:performCustomSelectionAction:] ()

#2 0x00000001b3512df8 in -[UITableView _didUpdateFocusInContext:withAnimationCoordinator:] ()

#3 0x0000000213b38988 in -[UITableViewAccessibility _didUpdateFocusInContext:withAnimationCoordinator:] ()

#4 0x00000001b2f54260 in __84-[UIFocusSystem _sendDidUpdateFocusNotificationsInContext:withAnimationCoordinator:]_block_invoke ()

#5 0x00000001b2f08944 in _UIFocusEnvironmentEnumerateAncestorEnvironments ()

#6 0x00000001b2f54480 in -[UIFocusSystem _sendNotificationsForFocusUpdateInContext:withAnimationCoordinator:usingBlock:] ()

#7 0x00000001b2f53ff0 in -[UIFocusSystem _sendDidUpdateFocusNotificationsInContext:withAnimationCoordinator:] ()

#8 0x00000001b2f53630 in -[UIFocusSystem _updateFocusWithContext:report:] ()

#9 0x00000001b2f5319c in -[UIFocusSystem updateFocusIfNeeded] ()

#10 0x00000001b2f561dc in __43-[UIFocusSystem _updateFocusUpdateThrottle]_block_invoke ()

#11 0x00000001b3725e70 in -[_UIAfterCACommitBlock run] ()

#12 0x00000001b37262cc in -[_UIAfterCACommitQueue flush] ()

#13 0x00000001b2851630 in _runAfterCACommitDeferredBlocks ()

#14 0x00000001b28513ac in _cleanUpAfterCAFlushAndRunDeferredBlocks ()

#15 0x00000001b28512c8 in _afterCACommitHandler ()

#16 0x00000001887b0db8 in CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION ()

#17 0x00000001887b0ca4 in __CFRunLoopDoObservers ()

This wasn't happening before. I'm not sure if it is related to the Ventura 13.2.1 update or if there is some minor tweak on my end that is causing this change in behavior though I'm not thrilling with UIKit making a selection without asking me about it.

I could live with the automatic row selection if the next row below the deleted row was automatically selected but sometimes it is not. Sometimes UITableView is auto selecting a row two cells back which doesn't make any sense to me.

Okay so I have two window scenes open (windows) and the auto selecting was happening in one window and not the other. I figured out how to trigger it: UITableView just starts doing this after I move the selection with the arrow keys shortly before doing a swipe delete. The focus system just acts bizarre.

I really didn't need to run into another one of these UITableView bugs... errr.. I'll see if I can come up with something to prevent it tomorrow. Anyone else got anything on this?

I filed FB12007198

So I attempted to workaround the issue by disabling table view focus just before doing the swipe delete action...then enabling it again after a bit of a delay in -tableView:didEndEditingRowAtIndexPath:

And that avoids the auto selecting, assuming I do it after a long enough delay since the focus system must be queuing all this up on timers. But if you click outside the window, then reactivate the window, the focus system just selects the first row automatically in the table view after focus is reenabled.

I could suppress it by returning NO from -tableView:shouldHighlightRowAtIndexPath: or canFocusOnItemAtIndexPath: but there is no good way to determine when I should suppress the selection to workaround this issue. Anyone know a way to tame the focus system? Can I clear its queue? A method like -cancelQueuedFocusSystemUpdateRequestsTakeItEasyPlease ?

Mac Catalyst: UITableView Suddenly Randomly Selecting Rows After Deleting Row Via Swipe Action After a Bit of A Delay
 
 
Q