ios - TableView showing wrong data after segue -


this project simple car's dictionary, using core data, .csv file uploaded server.

when select word in first tableview trigger second page read definition in tableview, there problem showing incorrect word , definition.

you ignoring section number in index path tableview.indexpathforselectedrow. sectioned table, need translate section/row combination data reference.

a standard way of doing array of arrays (e.g. dictionaryitems:[[dictionary]]). way, can array of items using index path section on outer array , specific item using index path row on array section reference returns.

--- update methods need code changes in dictionarytableviewcontroller

override func numberofsectionsintableview(tableview: uitableview) -> int {     // assume single section after search     return (searchcontroller.active) ? 1 : sectiontitles.count }   // create standard way dictionary index path func itemforindexpath(indexpath: nsindexpath) -> dictionary? {     var result: dictionary? = nil      if searchcontroller.active {         result = searchresults[indexpath.row]     } else {         let wordkey = sectiontitles[indexpath.section]         if let items = cockpitdict[wordkey] {             result = items[indexpath.row]         }     }     return result }  override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {      let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) as! dictionarytableviewcell      if let dictionary = itemforindexpath(indexpath) {         cell.wordlabel.text = dictionary.word         cell.definitionsmalllabel.text = dictionary.definition     } else {         print("cell error path \(indexpath)")     }      return cell }   override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {     if segue.identifier == "showdictionarydetail" {         if let indexpath = tableview.indexpathforselectedrow {             let destinationcontroller = segue.destinationviewcontroller as! dictionarydetailviewcontroller             if let dictionary = itemforindexpath(indexpath) {                 destinationcontroller.dictionary = dictionary             } else {                 print("segue error path \(indexpath)")             }             searchcontroller.active = false         }     } } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -