0

I have a view hierarchy as below:

-UIScrollView
--UITableView
---UIView

all of my code in project is:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:scrollView];

UITableView *tableView = [[UITableView alloc] initWithFrame:scrollView.bounds];
tableView.delegate = self;
tableView.dataSource = self;
[scrollView addSubview:tableView];

UIView *tableSubView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 20)];
[tableView addSubview:tableSubView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *idForCell = @"id";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:idForCell];
if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idForCell];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@",@(indexPath.row)];
return cell;
}

and my js code in Automation is:

var target = UIATarget.localTarget();
target.delay(2);
target.logElementTree();

finally I check element tree show in Trace Log by instruments,and the result is:

-UIATarget
--UIAApplication
---UIAWindow
----UIAScrollView
-----UIATableView
------UIATableCell
------UIATableCell
------UIATableCell

but I can't find the tableSubView element, can anyone tell me the reason?TKS very much!

Kaneki
  • 1
  • 3

2 Answers2

0

Try changing line

[tableView addSubview:tableSubView];

to

[tableView.superview addSubview:tableSubView];
Avaan
  • 4,709
  • 1
  • 10
  • 13
0

Sometimes, UIAutomation with Instruments is a little bit tricky. You can try several things,before calling target.logElementTree();:

  • Make scrollToVisible() to the tableView

    target.mainWindow().scrollViews()[0].tableViews()[0].scrollToVisible();

  • Add accesibility Label to the table subview. In your code:

    UIView *tableSubView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 20)]; tableSubView.accessibilityLabel = @"tableSubview";

You can combine both. I hope this will help you!

jmartinalonso
  • 2,324
  • 1
  • 19
  • 22