ali*_*ego 3 xcode searchable swift swiftui
我在 SwiftUI 中使用 .searchable 修饰符。有没有办法知道用户何时按下键盘上的搜索键?我知道如何使用 UIViewRepresentable 和 searchController 来做到这一点。我想知道是否有一种 SwiftUI 方法可以使用 .searchable 修饰符来做到这一点
小智 5
添加 .onSubmit(of: .search) 修饰符。像这样:
List {
ForEach(results, id: \.self) { result in
Text(result)
}
}
.searchable(text: $searchText)
.onSubmit(of: .search) {
// Search button tapped. Perform operation here
}
Run Code Online (Sandbox Code Playgroud)
如果适合您,请标记为正确答案。
| 归档时间: |
|
| 查看次数: |
1411 次 |
| 最近记录: |