ios - Loading an Array to TableView based on Segment-Control -


i relatively new swift. tried search , google problem can't find answers. shouldn't hard. hope guys can me out. i‘ve been struggling issue on days now:

i created tableview loads array of tuples .swift file. working fine! want tableview choose .swift based on "segment control". if segment-control switched "a" want show array of "psscbookmac.swift", b array of "psscbookwin.swift".

the action ist written properly, guess (print-statements working). change of segment-control doesn't effect tableview. guess: segment-control doesn't effect tableview because has been loaded before , can't change value. how can achieve that?

cheers answers!

here code:

import uikit  class viewcontroller: uiviewcontroller, uitableviewdatasource {     @iboutlet weak var psscsegmentcontrol: uisegmentedcontrol!      //load array psscbook.swift     var psscbook = psscbookmac()      @ibaction func psscsegmentcontrolchoose(sender: anyobject) {         if psscsegmentcontrol.selectedsegmentindex == 0 {             var psscbook = psscbookmac()             println("im mac")         } else {             var psscbook = psscbookwin()             println("im win")         }     }      func numberofsectionsintableview(tableview: uitableview) -> int {         return 2     }      func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {         if section == 0 {             return psscbook.pssctools.count         } else {             return psscbook.psscfile.count         }     }         func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {         var cell = tableview.dequeuereusablecellwithidentifier("pscell", forindexpath: indexpath) as! uitableviewcell         if indexpath.section == 0 {             let (shortcuttitle,shortcutkey) = psscbook.pssctools[indexpath.row]             cell.textlabel?.text = shortcuttitle             cell.detailtextlabel?.text = shortcutkey         } else {             let (shortcuttitle,shortcutkey) = psscbook.psscfile[indexpath.row]             cell.textlabel?.text = shortcuttitle             cell.detailtextlabel?.text = shortcutkey         }          /*  var psicon = uiimage(named: "psicon")         cell.imageview?.image = psicon */          return cell     }      func tableview(tableview: uitableview, titleforheaderinsection section: int) -> string? {         if section == 0 {             return "tools"         } else {             return "file"         }     } } 

when update datasource of table view, won't magically update itself.

you have reload table view changes take place:

@ibaction func psscsegmentcontrolchoose(sender: anyobject) {     if psscsegmentcontrol.selectedsegmentindex == 0 {         var psscbook = psscbookmac()         println("im mac")     } else {         var psscbook = psscbookwin()         println("im win")     }     self.tableview.reloaddata(); } 

Comments