最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift中UITableView的index无法定位

Swift crifan 2451浏览 0评论

需要点击:

A-Z的字母的时候,可以定位到对应的位置

之前已经实现了:

    //right side: "A" … "Z"
    func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
        print("sectionIndexTitlesForTableView")
        print("contactIndexTitleList=\(contactIndexTitleList)")
        return contactIndexTitleList
    }
   
    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        print("titleForHeaderInSection: section=\(section)")
        if isFixedTopSection(contactSectionItemList[section]) {
            //fixed top section, no section title
            return nil
        }
        else
        {
            return contactSectionItemList[section].indexTitle
        }
    }

搜:

ios tableview locate section via index title

ios tableview  index title

iOS 之 UITableView 使用索引 – Carl_Huang的个人页面 – 开源中国社区

swift uitableview index title

Swift – 给表格UITableView添加索引功能(快速定位)

最后在原油基础上,加上:

    //right side: "A" … "Z"
    func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
        print("sectionIndexTitlesForTableView")
        print("contactIndexTitleList=\(contactIndexTitleList)")
        return contactIndexTitleList
    }
   
    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        print("titleForHeaderInSection: section=\(section)")
        if isFixedTopSection(contactSectionItemList[section]) {
            //fixed top section, no section title
            return nil
        }
        else
        {
            return contactSectionItemList[section].indexTitle
        }
    }
   
    // tell table which section corresponds to section title/index (e.g. "B",1))
    func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
        var titleIdx = 0
        for (sectionIndex, eachSection) in contactSectionItemList.enumerate() {
            if title == eachSection.indexTitle {
                titleIdx = sectionIndex
                break
            }
        }
       
        print("title=\(title), index=\(index) -> titleIdx=\(titleIdx)")
        return titleIdx
    }

转载请注明:在路上 » [已解决]swift中UITableView的index无法定位

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.169 seconds, using 22.17MB memory