Cant access TableViewCell elements using UI Automation
I have a custom Table View Cell that displays the details of a Conference Call. The body of the cell's constructor is below:
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString*) reuseIdentifier {
if(self = [super initWithStyle:UITableVie开发者_高级运维wCellStyleDefault reuseIdentifier:reuseIdentifier]) {
self.contentView.isAccessibilityElement = YES;
self.contentView.accessibilityLabel = @"Blah";
conferenceNameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
conferenceNameLabel.adjustsFontSizeToFitWidth = YES;
conferenceNameLabel.font = [UIFont systemFontOfSize:14];
conferenceNameLabel.isAccessibilityElement = YES;
conferenceNameLabel.accessibilityLabel = @"Name";
[self.contentView addSubview:conferenceNameLabel];
conferenceDateLabel = [[UILabel alloc] initWithFrame:CGRectZero];
conferenceDateLabel.adjustsFontSizeToFitWidth = YES;
conferenceDateLabel.font = [UIFont systemFontOfSize:14];
conferenceDateLabel.isAccessibilityElement = YES;
conferenceDateLabel.accessibilityLabel = @"Date";
[self.contentView addSubview:conferenceDateLabel];
recurringIconView = [[UIImageView alloc] initWithFrame:CGRectZero];
[recurringIconView setContentMode:UIViewContentModeScaleAspectFit];
recurringIconView.isAccessibilityElement = YES;
recurringIconView.accessibilityLabel = @"Icon";
[self.contentView addSubview:recurringIconView];
[self setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
return self;
}
When using UI Automation, I can access the Content View using the accessibility label "Blah". But I cant access any of my Labels or my ImageView. Any reason why I can't get at those UI elements using UI automation?
Within your script, you should be able to log out the accessibility hierarchy for each cell using logElementTree():
cell.logElementTree();
These subview should appear in that logged tree, along with their accessibility labels.
If you somehow can't address these elements by their label, you should be able to grab them by their relative position in the list of sibling views:
var firstLabel = cell.elements()[0];
I walk through UI Automation and show examples of how to test out table views like this in my course on iTunes U.
精彩评论