Search code examples
iosios8uinavigationcontrolleruinavigationitemkif

Pressing back button (backBarButtonItem) in KIF?


Does KIF provide any special support for tapping back buttons or will I have to do something like this?

// in parent ViewController

self.navigationItem.backBarButtonItem.isAccessibilityElement = YES;
self.navigationItem.backBarButtonItem.accessibilityLabel     = @"Back";

// in test class

[tester tapViewWithAccessibilityLabel: @"Back"]];

The latter would be a bit unfortunate, because my code currently does not have back buttons at all and self.navigationItem.backBarButtonItem is and can normally remain nil (see here): the description in the storyboard suffices so far.


Solution

  • By default, the back button will be labeled "Back" and accessible to VoiceOver as such as well so:

    [tester tapViewWithAccessibilityLabel: @"Back"];
    

    will work if you haven't done anything else.

    So assuming I understand the structure of your view controllers (which is navigation, but with no explicit backBarButtonItem set), then what you have should work without the parent view controller changes you're worried about.