4

In our application we display a list of items and each item has an image which can either be hidden or displayed.

The issue is that if the image is initially hidden, when we set hidden = false, the image is displayed but the Accessibility Inspector doesn't identify it.

If we call reloadRows then the image is identified by Accessibility Inspector.

However, I want to avoid calling reloadRows when the visibility of the image changes because it adds complexity (weird dependencies).

What I've tried so far is the following:

  • call setNeedsDisplay() on the cell
  • post UIAccessibilityLayoutChangedNotification

Neither work.

Any other ideas of "refreshing / reloading" the cell so the Accessibility Inspector identifies the image?

Please note that I did set an accessibility identifier and isAccessibilityElement is set to true, since after calling reloadRows the image is identified.

Thanks, Cosmin

Cosmin
  • 2,840
  • 5
  • 32
  • 50

2 Answers2

2

The issue here is due to stack view. If you keep the image view outside the stack view, it should work fine. But since, you are placing it inside the stack view, and by default it's hidden, when the cell loads, accessibility order is determined in such a way that no such element(imageview) exists as it was hidden and stack view shifted other views in image view's place. To make the accessibility inspector read the image view, you need to reload the cell with image view as visible and this time it would work fine.

Alternative to reloading, you can define accessibilityElements for the cell and add image view, if visible, on the basis of isHidden property.

This would make the image view accessibile.

imshail31
  • 56
  • 3
0

I have ended up making the UIImageView always visible and assign null to the image when I want to hide it, leveraging its intrinsic content size for any layout changes (forgot to mention that the UIImageView was contained by a StackView so by hiding it the StackView ended up shifting the other views - a behaviour that I wanted to keep)

Cosmin
  • 2,840
  • 5
  • 32
  • 50