Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the order of accessibility elements in a view controller without losing access to the navigation bar?

I've got a view controller that contains a table view along with a few "floating" controls that appear visually at the bottom of the screen.

When navigating with VoiceOver, it would make more sense for the user to navigate like:

  • back button (navigation bar)
  • title (navigation bar)
  • edit button (navigation bar)
  • floating button
  • table contents

But currently, the navigation order is

  • back button (navigation bar)
  • title (navigation bar)
  • edit button (navigation bar)
  • table contents
  • floating button

When I explicitly set the accessibility elements for my view controller's view to change the order like

- (void)viewDidLoad {
  self.accessibilityElements = @[self.floatingButton, self.tableView];
}

the navigation order becomes

  • floating button
  • table contents

and the navigation bar is no longer accessible.

If I include self.navigationController.navigationBar at the beginning of the accessibilityElements array, then I get the navigation order

  • back button (navigation bar)
  • title (navigation bar)
  • edit button (navigation bar)

and swiping right again navigates back to the back button, so I can't reach the floating button or table contents.

Is there a way to reorder the accessible subviews without also losing access to the navigation bar?

like image 946
Greg Avatar asked Sep 10 '25 21:09

Greg


1 Answers

I tried and reproduce the problem you mentioned in a blank project following this storyboard : enter image description here I read this a11y recommendations site to provide this code snippet I implemented to make it work as desired :

class TestButtonTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var myTableView: UITableView!
    @IBOutlet weak var bottomButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        myTableView.delegate = self as UITableViewDelegate
        myTableView.dataSource = self as UITableViewDataSource
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.accessibilityElements = [bottomButton, myTableView]
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView,
                   numberOfRowsInSection section: Int) -> Int {
        return 2
    }

    func tableView(_ tableView: UITableView,
                   cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        return zeCell = tableView.dequeueReusableCell(withIdentifier: "myPersoCell",
                                               for: indexPath)
    }
}

I made right flicks to get the next elements and obtained the illustrations hereunder : enter image description here enter image description here The VoiceOver navigation follows the desired pattern :

  1. Back button (navigation bar).
  2. Title (navigation bar).
  3. Edit button (navigation bar).
  4. Floating button.
  5. Table contents.

I specified nothing in particular and changed the order of accessibility elements in a view controller without losing access to the navigation bar.

like image 74
XLE_22 Avatar answered Sep 13 '25 11:09

XLE_22