Call dictionary in tableView of swift -


how call dictionary values in tableview..

getting error

import uikit  class viewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate{      @iboutlet var tblview: uitableview!     var animalname = ["e":["elephant","eee"","l":["lion","ll"],h":["horse",huh"]]     var initial = array(animalname.alkeys)   //error in line      func numberofsectionsintableview(tableview: uitableview) -> int {         return 1     }      func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {         return animalname.count     }      func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {         var cell = tableview.dequeuereusablecellwithidentifier("cell")! uitableviewcell          cell.textlabel?.text = animalname[indexpath.row]  //how call cell          return cell      }      func sectionindextitlesfortableview(tableview: uitableview) -> [string]? {         return initial                         // not getting output     }      func tableview(tableview: uitableview, sectionforsectionindextitle title: string, atindex index: int) -> int {         return index                           // how select      }      override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.     }  } 

import uikit  class viewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate{     @iboutlet var tblview: uitableview!    var animalname = ["e":["elephant","eee"], "l":["lion","ll"], "h":["horse", "huh"]]    var initial: [string] = []   //error in line     func numberofsectionsintableview(tableview: uitableview) -> int {       return self.initial.count    }     func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {       if let animalsofsection = self.animalname[self.initial[section]] {          return animalsofsection.count       }       return 0    }     func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {       let cell = tableview.dequeuereusablecellwithidentifier("cell")! uitableviewcell        if let animal = self.animalname[self.initial[indexpath.section]]?[indexpath.row] {          cell.textlabel?.text = animal  //how call cell       }         return cell     }     func sectionindextitlesfortableview(tableview: uitableview) -> [string]? {       return self.initial                         // not getting output    }     func tableview(tableview: uitableview, sectionforsectionindextitle title: string, atindex index: int) -> int {       if let index = self.initial.indexof(title) {          return index                           // how select       }       return 0    }     override func viewdidload() {       super.viewdidload()       // additional setup after loading view, typically nib.       self.initial = array(self.animalname.keys).sort(<)    } } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -