From 65a76675046b3acd81c4988034dcd64625a0dc1c Mon Sep 17 00:00:00 2001 From: dostrander Date: Wed, 3 Nov 2021 09:52:58 -0400 Subject: [PATCH] Check that we have the same view after scrolling This can be changed because of cell reuse --- .../KIF/Additions/UIAccessibilityElement-KIFAdditions.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/KIF/Additions/UIAccessibilityElement-KIFAdditions.m b/Sources/KIF/Additions/UIAccessibilityElement-KIFAdditions.m index fc155dd1..1dede63c 100644 --- a/Sources/KIF/Additions/UIAccessibilityElement-KIFAdditions.m +++ b/Sources/KIF/Additions/UIAccessibilityElement-KIFAdditions.m @@ -219,6 +219,15 @@ + (UIView *)viewContainingAccessibilityElement:(UIAccessibilityElement *)element // Give the scroll view a small amount of time to perform the scroll. CFTimeInterval delay = animationEnabled ? 0.3 : 0.05; KIFRunLoopRunInModeRelativeToAnimationSpeed(kCFRunLoopDefaultMode, delay, false); + + // Because of cell reuse the first found view could be different after we scroll. + // Find the same element's view to ensure that after we have scrolled we get the same view back. + UIView *checkedView = [UIAccessibilityElement viewContainingAccessibilityElement:element]; + // intentionally doing a memory address check vs a isEqual check because + // we want to ensure that the memory address hasn't changed after scroll. + if(view != checkedView) { + view = checkedView; + } } }