【问题标题】:iPhone UIAutomation:can't find sub-element of tableviewiPhone UIAutomation:找不到表格视图的子元素
【发布时间】:2016-01-14 07:17:13
【问题描述】:

我的视图层次结构如下:

-UIScrollView
--UITableView
---UIView

我在项目中的所有代码都是:

- (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;
}

我在自动化中的 js 代码是:

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

最后我通过仪器检查了 Trace Log 中的元素树显示,结果是:

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

但是我找不到tableSubView元素,有谁能告诉我原因吗?TKS非常多!

【问题讨论】:

    标签: ios ios-ui-automation xcode-instruments


    【解决方案1】:

    换行试试

    [tableView addSubview:tableSubView];
    

    [tableView.superview addSubview:tableSubView];
    

    【讨论】:

      【解决方案2】:

      有时,带有 Instruments 的 UIAutomation 有点棘手。您可以尝试几件事,然后再致电target.logElementTree();

      • 将 scrollToVisible() 设置为 tableView

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

      • 为表格子视图添加可访问性标签。在您的代码中:

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

      您可以将两者结合起来。希望对您有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-08
        相关资源
        最近更新 更多