gpt4 book ai didi

ios - 辅助功能看不到 SWTableViewCell 的实用程序按钮

转载 作者:行者123 更新时间:2023-12-03 18:25:21 26 4
gpt4 key购买 nike

我正在使用 SWTableviewCell我可以向左滑动并显示带有 XCTest 和辅助功能的实用程序按钮,但没有找到这些元素。使用 Accessibility Inspector 仔细检查。

由于 SWTableViewCell 中的实用程序按钮是常规的 UIButton,因此它应该开箱即用。还尝试设置按钮的辅助功能标签。

任何帮助将不胜感激。谢谢!

更新:这是我的代码:

    // This works
app = XCUIApplication()
let firstCell = app.tables.cells.elementBoundByIndex(0)
firstCell.swipeLeft()

// Following 2 TODO's doesn't work
// TODO: tap More button
firstCell.buttons["More"].tap()
XCTAssertEqual(app.sheets.count, 1, "'More' action sheet should be present")
// TODO: assert sheet doesn't contain Lock/Unlock button
let sheet = app.sheets.element
let lockButton = sheet.buttons["Lock"]
sheet.buttons["Cancel"].tap()

最佳答案

结束了为我的 UITableViewCell 子类覆盖 UIAccessibilityContainer 方法,如下所示:

- (NSArray *)accessibilityElements {
if (_accessibilityElements == nil) {
_accessibilityElements = [[NSMutableArray alloc] initWithCapacity: 2];
[_accessibilityElements addObject: self.miscLabel];
[_accessibilityElements addObject: self.titleLabel];
}
return _accessibilityElements;
}

- (nullable id)accessibilityElementAtIndex:(NSInteger)index {
return _accessibilityElements[index];
}

- (NSInteger)indexOfAccessibilityElement:(id)element {
return [_accessibilityElements indexOfObject: element];
}

注意 _accessibilityElements 是我的单元格的实例变量:

@interface MyCell : SWTableViewCell
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *miscLabel;
...
@property (strong, nonatomic) NSMutableArray *accessibilityElements;

@end

然后,实现 SWTableViewCellDelegate 方法来添加和删除辅助功能按钮:

- (void)swipeableTableViewCellDidEndScrolling:(MyCell *)cell {
NSMutableArray *utilityButtons = cell.accessibilityElements;
if (cell.isUtilityButtonsHidden) {
[utilityButtons removeObjectsInArray: cell.rightUtilityButtons];
}
else {
[utilityButtons addObjectsFromArray: cell.rightUtilityButtons];
}
}

关于ios - 辅助功能看不到 SWTableViewCell 的实用程序按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33012382/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com