Search code examples
iosuitabbarcontrolleruinavigationitemvoiceover

Voice over : UIAccessibilityLayoutChangedNotification in ViewWillAppear is not setting focus on Navigation bar title every time the view is loaded


I have been struggling for last 2 days to figure this out. I have a UITabBarController and each tab has a UINavigationController with in the view. When i load the tab bar controller voice over is reading the tab view navigation bar title correctly. It works for the first time the view is loaded.(Seems like that is the default behavior.) But when i select the tabs again, voice over is reading the tab information but not setting the focus to the navigation bar title. Is there a way to set it to focus on the title every time the tab view is loaded. I tried using

override func viewWillAppear(_ animated: Bool) {
   super.viewWillAppear(animated)     

   UIAccessibilityPostNotification 
            (UIAccessibilityLayoutChangedNotification, self.navigationItem.titleView)
}

I also tried creating a label as title view and setting it up as a NavigationItem.

Nothing helped.

Any suggestions are greatly appreciated.

Thankyou.


Solution

  • Try in viewDidAppear not in viewWillAppear

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.navigationItem.titleView);
        });
    }