SwiftUI列表的右侧带有节索引? [英] SwiftUI List with Section Index on right hand side?
本文介绍了SwiftUI列表的右侧带有节索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以像在SwiftUI中的以下示例一样,在右侧具有一个带有索引的列表?
Is it possible to have a List with an index on the right hand side, like the example below in SwiftUI?
推荐答案
我一直在寻找解决同一问题的方法,但目前,我们目前唯一可能的选择是使用 UITableView
作为视图.
I was looking for a solution to the same question , but it currently the only option that we might have right now is using UITableView
as View.
import SwiftUI
import UIKit
struct TableView: UIViewRepresentable {
func makeUIView(context: Context) -> UITableView {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.delegate = context.coordinator
tableView.dataSource = context.coordinator
return tableView
}
func updateUIView(_ uiView: UITableView, context: Context) {
}
func makeCoordinator() -> Coordinator {
Coordinator()
}
final class Coordinator: NSObject, UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellId = "cellIdentifier"
let cell = tableView.dequeueReusableCell(withIdentifier: cellId) ?? UITableViewCell(style: .default, reuseIdentifier: cellId)
cell.textLabel?.text = "\(indexPath)"
return cell
}
func sectionIndexTitles(for tableView: UITableView) -> [String]? {
["a", "b"]
}
}
这篇关于SwiftUI列表的右侧带有节索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文