gpt4 book ai didi

swift - 创建没有 tableView 部分的 indexList?

转载 作者:行者123 更新时间:2023-11-28 07:33:53 25 4
gpt4 key购买 nike

我的表格 View 有一个部分,其中一个数组显示为行。我正在尝试创建一个显示在右侧的索引列表,我可以对其进行自定义,并将跳转到特定行。到目前为止,我能够显示索引,但单击字母时它不会跳转到特定行。当按下“A”时它将跳回第一行,但其他索引选择均无效。有解决办法吗?

编辑:一直在研究答案,但仍然找不到解决这个问题的方法。

   let respiratory = ["A - Patient Disposition Form","B - On Scene Physician","C - APGAR Score","D - LA Prehospital Stroke Screen","E - Pain Scales","F - Restraint Checklist","G - Abbreviations","H - Reperfusion Checklist","I - Difficult Airway","J - Burn Resources","DNR","NCCEP Airway Evaluation Form","NC MOST Form","PREMIS Preliminary Report","NC Eye Bank"]

let indexList = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","AA"]

func sectionIndexTitles(for tableView: UITableView) -> [String]? {
return indexList;
}
func sectionIndexTitlesForTableView( for tableView: UITableView) -> [AnyObject]! {
return respiratory as [AnyObject]
}
@IBOutlet weak var animalTableView: UITableView!




///Set elements in cell
func tableView( _ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "appendicieslist"/*Identifier*/, for: indexPath)
cell.textLabel?.text = respiratory[indexPath.row]
// FONT STYLE
cell.textLabel?.textColor = UIColor.white
cell.detailTextLabel?.font = UIFont.boldSystemFont(ofSize: 30.0)
cell.textLabel?.textAlignment = .center
self.animalTableView.backgroundColor = UIColor.clear
cell.textLabel?.backgroundColor = UIColor.black

return cell
}



func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return respiratory.count
}

最佳答案

要注意的是,您使用的 TableView 包含一个部分和许多行(而不是许多部分只有一行),但索引是通过引用部分而不是行来操作的。

来自UITableView类文档:

A table view can have an index that appears as a bar on the right hand side of the table (for example, "A" through "Z"). You can touch a particular label to jump to the target section.

一旦您移动到基于部分的表格 View ,您可以通过实现可选函数 tableView(_:sectionForSectionIndexTitle:at:) 实现对索引提供的导航的更细粒度控制。 .

始终可以编写您自己的自定义索引,为行而不是部分复制 UITableView 索引的功能,但根据您的用例,这可能效率低下或不合适。

关于swift - 创建没有 tableView 部分的 indexList?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53809065/

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