2011-06-16 47 views
3

我試圖在iPhone上設置一些UIAutomation測試。每當我在主窗口上執行logElementTree()時,我的所有UIATableView元素都有名稱「空列表」。我已經嘗試在相應的XIB文件中設置名稱,但一旦數據加載完畢,名稱就會再次設置爲「空列表」。下面是輸出的從調用logElementTree()的示例:UIATableView始終命名爲「空列表」

4) UIATableView [name:Empty list value:rows 1 to 1 of 1 rect:{{x:0, y:64}, {width:320, height:416}}] 
5) UIATableCell [name:OfferCardTableViewCell value:(null) rect:{{x:0, y:160}, {width:320, height:416}}] 
6) UIAWebView [name:(null) value:(null) rect:{{x:0, y:160}, {width:320, height:418}}] 
6) UIAWebView [name:(null) value:(null) rect:{{x:320, y:160}, {width:320, height:418}}] 
6) UIAWebView [name:(null) value:(null) rect:{{x:640, y:160}, {width:320, height:418}}] 

正如你可以看到,表視圖不是空的。有誰知道我如何確保UIATableView元素的名稱不是「空列表」?有沒有我不在某個地方實施的代表?

+0

這裏編寫代碼來解釋一下。 – Rodrigo 2011-06-16 19:48:43

回答

1

您想爲UITableView設置accessibilityLabel。至少在Xcode 4中,您無法在Interface Builder中設置此屬性,因此您必須以編程方式進行設置。

1

元素名稱來源於底層視圖的輔助功能屬性。如果指定了標識符屬性字符串,則該字符串將用作名稱;否則,使用標籤屬性字符串作爲名稱。與標籤方法相反。

不要使用輔助功能標籤來標識元素,請使用輔助功能標識符。

在Interface Builder中,可以使用運行時設置的標識屬性:

開放Identity Inspector - User Defined Runtime Attributes

Key Path: accessibilityIdentifier 
Type: String 
Value: <your identifier>