ios – 如何在swift中设置tableview中的索引

ios – 如何在swift中设置tableview中的索引,第1张

概述我无法正确理解如何将其转换为 Swift.有人能帮助我吗?我显然需要提高我对Objective-C的理解:( var animals : [String : [String]] =["B" : ["Bear", "Black Swan", "Buffalo"], "C" : ["Camel", "Cockatoo"], "D" : ["Dog", "Donkey"], " 我无法正确理解如何将其转换为 Swift.有人能帮助我吗?我显然需要提高我对Objective-C的理解:(

var animals : [String : [String]] =["B" : ["Bear","Black Swan","buffalo"],"C" : ["Camel","Cockatoo"],"D" : ["Dog","Donkey"],"E" : ["Emu"],"G" : ["Giraffe","Greater Rhea"],"H" : ["Hippopotamus","Horse"],"K" : ["Koala"],"L" : ["lion","Llama"],"M" : ["Manatus","Meerkat"],"P" : ["Panda","Peacock","Pig","Platypus","Polar Bear"],"R" : ["Rhinoceros"],"S" : ["Seagull"],"T" : ["Tasmania Devil"],"W" : ["Whale","Whale Shark","Wombat"]]var animalSection = [String]()var rev = [String]()var animalindexTitles = ["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"];overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    // Do any additional setup after loading the vIEw,typically from a ni    animalSection = animals.keys.array    rev = sorted(animalSection,{ (s1,s2) -> Bool in        return s1 <= s2    })    println(rev)}func numberOfSectionsIntableVIEw(tableVIEw: UItableVIEw) -> Int {    return animalSection.count}func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int {  var sectionTitle = rev[section]   // String    var sectionAnimals : [String] = animals[sectionTitle]! // String Array    return sectionAnimals.count}func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell {    let cell: AnyObject = tableVIEw.dequeueReusableCellWithIDentifIEr("cell",forIndexPath: indexPath)    var sectionTitle = rev[indexPath.section]    var sectionAnimals : [String] = animals[sectionTitle]!    var animal = sectionAnimals[indexPath.row]    cell.textLabel.text = animal    return cell as UItableVIEwCell    }func tableVIEw(tableVIEw: UItableVIEw,TitleForheaderInSection section: Int) -> String? {    return rev[section]}func sectionIndexTitlesFortableVIEw(tableVIEw: UItableVIEw) -> [AnyObject]! {    return animalindexTitles}func tableVIEw(tableVIEw: UItableVIEw,sectionForSectionIndexTitle      Title: String,atIndex index: Int) -> Int{ return 0}

这里有很快的代码检查它
这是可选的,没有提到它
由于swift在某些方面比面向对象更具功能性(并且Arrays是结构,而不是对象),因此使用函数“find”对数组进行 *** 作,该函数返回一个可选值,因此请准备好处理nil值:

解决方法
rev  = sorted(animalSection,s2) -> Bool in        return s1 <= s2    })    println(rev)    ns = rev func tableVIEw(tableVIEw: UItableVIEw,sectionForSectionIndexTitle Title: String,atIndex index: Int) -> Int {  return ns.indexOfObject(Title)    }

我希望这项工作

总结

以上是内存溢出为你收集整理的ios – 如何在swift中设置tableview中的索引全部内容,希望文章能够帮你解决ios – 如何在swift中设置tableview中的索引所遇到的程序开发问题。

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

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

原文地址: http://www.outofmemory.cn/web/1025981.html

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

发表评论

登录后才能评论

评论列表(0条)

保存