ios – Swift – 如何创建正确的sectionForSectionIndexTitle?

ios – Swift – 如何创建正确的sectionForSectionIndexTitle?,第1张

概述我有一个包含完整字母的部分索引 – 但是,我的表中的部分只包含几个字母(例如C,F,N,U). 我想修改sectionForSectionIndexTitle以在滑动手指超过部分索引时正确显示右侧部分.我仍然不确定如何使用sections.append … 谢谢你的帮助. 这是我的代码的样子: Section.swift struct Section{ var heading : Str 我有一个包含完整字母的部分索引 – 但是,我的表中的部分只包含几个字母(例如C,F,N,U).

我想修改sectionForSectionIndexTitle以在滑动手指超过部分索引时正确显示右侧部分.我仍然不确定如何使用sections.append …

谢谢你的帮助.

这是我的代码的样子:

Section.swift

struct Section{    var heading : String    var items : [String]    init(Title: String,objects : [String]) {        heading = Title        items = objects    }}

VIEwController.swift

func updateSections(index : Int) {    switch index {    case 0:        sections.append(Section(Title: "C",objects: ["Czech Republic"]))        sections.append(Section(Title: "F",objects: ["France"]))        sections.append(Section(Title: "N",objects: ["norway"]))        sections.append(Section(Title: "U",objects: ["USA"]))    default: break    }    tableVIEwOutlet.reloadData()}let arrIndexSection = ["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"]func sectionIndexTitlesFortableVIEw(tableVIEw: UItableVIEw) -> [String]? {    if segmentedControlOutlet.selectedSegmentIndex == 0 {        return arrIndexSection    } else {        return [""]    }}func tableVIEw(tableVIEw: UItableVIEw,sectionForSectionIndexTitle Title: String,atIndex index: Int) -> Int {    let temp = arrIndexSection as NSArray    return temp.indexOfObject(Title)}func numberOfSectionsIntableVIEw(tableVIEw: UItableVIEw) -> Int {    return sections.count}func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int {    let section = sections[section]    return section.items.count}func tableVIEw(tableVIEw: UItableVIEw,TitleForheaderInSection section: Int) -> String? {    return sections[section].heading}
解决方法 尝试在项目中使用以下代码:

func tableVIEw(tableVIEw: UItableVIEw,atIndex index: Int) -> Int {    var tempIndex:Int = 0    for str in arrIndexSection {        if str == Title {            return tempIndex        }        tempIndex += 1    }    return 0}
总结

以上是内存溢出为你收集整理的ios – Swift – 如何创建正确的sectionForSectionIndexTitle?全部内容,希望文章能够帮你解决ios – Swift – 如何创建正确的sectionForSectionIndexTitle?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1043973.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存