admin管理员组文章数量:1386710
accessibilityIdentifier
is getting added multiple times when added inside for loop.
Below is my code
class viewModel {
var availableSectionWithElements: [String: [String]]? = ["fruits" : ["Mangoes", "bananas"], "veg": ["Tomato", "carrots"]]
}
Struct mainView {
VStack {
ForEach(viewModel.availableSectionWithElements.indices, id: \.self) { index in
let sectionTitle = viewModel.availableSectionWithElements[index].title
Section {
ForEach(viewModel.availableSectionWithElements[index].elements, id: \.self) { item in
NavigationLink(value: item) {
CellView(viewModel: viewModel.moreCellViewModel(element: item))
.accessibilityIdentifier("k")
}
}
}
header: {
MoreHeaderView(title: sectionTitle)
.accessibilityIdentifier("\(HeaderView.self)\(index)")
}
}
}
}
My accessbilityIdentifier
is k-k-k when seen in Accessibility Inspector.
How to make sure to add accessibility identifier only once per view?
accessibilityIdentifier
is getting added multiple times when added inside for loop.
Below is my code
class viewModel {
var availableSectionWithElements: [String: [String]]? = ["fruits" : ["Mangoes", "bananas"], "veg": ["Tomato", "carrots"]]
}
Struct mainView {
VStack {
ForEach(viewModel.availableSectionWithElements.indices, id: \.self) { index in
let sectionTitle = viewModel.availableSectionWithElements[index].title
Section {
ForEach(viewModel.availableSectionWithElements[index].elements, id: \.self) { item in
NavigationLink(value: item) {
CellView(viewModel: viewModel.moreCellViewModel(element: item))
.accessibilityIdentifier("k")
}
}
}
header: {
MoreHeaderView(title: sectionTitle)
.accessibilityIdentifier("\(HeaderView.self)\(index)")
}
}
}
}
My accessbilityIdentifier
is k-k-k when seen in Accessibility Inspector.
How to make sure to add accessibility identifier only once per view?
Share Improve this question edited Mar 18 at 0:26 soundflix 2,86512 gold badges16 silver badges34 bronze badges asked Mar 17 at 15:13 AppleDeveloperAppleDeveloper 1,4593 gold badges21 silver badges52 bronze badges1 Answer
Reset to default 0Instead of giving each CellView
the same identifier "k", use some unique value like this:
...
CellView(viewModel: viewModel.moreCellViewModel(element: item))
.accessibilityIdentifier("Cell_\(item)")
...
本文标签: iosHow to make sure to add accessibility identifier only once per view in SwiftUIStack Overflow
版权声明:本文标题:ios - How to make sure to add accessibility identifier only once per view in SwiftUI? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744551857a2612230.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论