Accessibility: How to always set the focus on the navigation item's title view

roplacebo picture roplacebo · Apr 9, 2013 · Viewed 9.2k times · Source

I'm using a UINavigationController in my app. When using VoiceOver the backButton has the focus, when a new ViewController is pushed.

I'd rather have the accessibilityLabel of the titleView been focused if the view appears, so that its accessibilityLabel is read first.

Using UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.navigationItem);the titleView seems to be focused, when I create and push the view controller for the first time. But when I come back from another view controller (pushed onto the first one), the focus is on the back button again.

Answer

roplacebo picture roplacebo · Apr 10, 2013

I should've set the the accessibilityLabel of the titleView, not the navigationItem. The following works:

- (void) viewDidLoad
{
   ...
   self.navigationItem.titleView.accessibilityLabel = @"[text-to-speak]";
}
- (void) viewDidAppear
{
  [super viewDidAppear];       
  UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.navigationItem.titleView);
}