Search code examples
iosobjective-cuiaccessibility

iOS UIAccessibility - Is it possible to access elements in dynamically added views?


Is it possible to access accessibility elements inside of dynamically added subviews?

For example, I have a subview that contains and image and some text. After a certain user event, the subview is added for a certain period of time to the main view and then removed. Is it possible for accessibility to access the static text and image inside this "makeshift" subview?

Thanks


Solution

  • Yes. Experiment using VoiceOver. If VoiceOver is unable to select the views, you may need to post an notification alerting accessibility clients that the screen contents have changed:

    UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification,
                                    elementToFocusIfAny);
    

    If you need the text and image to be selectable, ensure that their container view is not an accessibility element:

    isAccessibilityElement = NO
    

    If you have any further trouble, refer to the Accessibility Programming Guide for iOS or return to Stack Overflow with your new question.