我在我的應用中顯示UITabBar
,並試圖將accessibilityIdentifier
分配給按鈕。要做到這一點,我用下面的行中的每個我的視圖控制器實例化:將accessibilityIdentifier添加到UITabBarButton
viewController.tabBarItem.accessibilityIdentifier = @"ViewControllerID";
這些viewControllers所有被添加到UITabBar
像這樣:
NSMutableArray *tabBarItems = [NSMutableArray array];
for (NSInteger i=0; i<_viewControllers.count; i++) {
UIViewController *viewController = [_viewControllers objectAtIndex:i];
[viewController setCommonTabBarController:self];
[self addChildViewController:viewController];
if (i == 0) {
viewController.view.frame = self.currentTabView.bounds;
[self.currentTabView addSubview:viewController.view];
[self addConstraintsToSubView:viewController.view];
_selectedViewController = viewController;
_selectedIndex = 0;
}
[viewController didMoveToParentViewController:self];
[tabBarItems addObject:[viewController tabBarItem]];
}
[self.tabBar setItems:tabBarItems animated:animated];
所以,我覺得應該發生在這裏,我們抓取的tabBarItem
已正確設置了accessibilityIdentifier
(當我設置斷點時,每個視圖控制器的accessibilityIdentifier
是我期望的。)然後,實際顯示時,沒有accessibilityIdentifier
。
事情我已經注意到:
的iOS使用UITabBarButton
代替UITabBarItem
。我認爲這與它有關。當我打印出標籤欄的items
數組時,每個項目都有正確的accessibilityIdentifier
,但是,任何UITabBarButton
對象都沒有關聯標籤欄項目的accessibilityIdentifier
。
有誰知道爲什麼輔助功能標識符不是,因爲缺少一個更好的詞,「攜帶」到iOS使用的UITabBarButton
對象?
我看到相同的行爲,我想這是值得向蘋果提交一個雷達。 –
您是否曾經爲此找到過解決方法或解決方法?我正在實現UITests,並試圖獲得正確的tabBarItem而不依賴於按鈕(本地化)中的標題。 – Sti