ios - numberOfRowsInSection not overriding Attributes Inspector -


in swift 2, working on uitableview dynamically create cells based on contents of dictionary. dictionary has 38 entries. when manually set table view section have 38 rows in attributes inspector, works expected.

however, isn't ideal, , i'd rather use numberofrowsinsection count of dictionary , create rows/cells way. when att inspector set 1, out of bounds error.

terminating app due uncaught exception 'nsrangeexception', reason: '*** -[__nsarrayi objectatindex:]: index 1 beyond bounds [0 .. 0]' 

here code:

import swiftyjson import uikit  class ourtableviewcontroller2: uitableviewcontroller {       @iboutlet weak var menubutton: uibarbuttonitem!      var labels = [string: uilabel]()     var strings = [string]()     var objects = [[string: string]]()      override func viewdidload() {         super.viewdidload()          tableview.datasource = self         tableview.delegate = self          self.tableview.registerclass(uitableviewcell.self, forcellreuseidentifier: "cell")          //gets data used cells         let urlstring = "http://handheldart.org/api/tags/"         if let url = nsurl(string: urlstring) {             if let data = try? nsdata(contentsofurl: url, options: []) {                 let json = json(data: data)                 parsejson(json)             }         }          //menu button @ top left of screen         if self.revealviewcontroller() != nil {             menubutton.target = self.revealviewcontroller()             menubutton.action = "revealtoggle:"             self.view.addgesturerecognizer(self.revealviewcontroller().pangesturerecognizer())         }      }      //creates array 'objects'     func parsejson(json: json) {         result in json.arrayvalue {             let id = result["id"].stringvalue             let tagurl = result["url"].stringvalue             let tagname = result["name"].stringvalue             let obj = ["id": id, "tagurl": tagurl, "tagname": tagname]             //print (tagname)             objects.append(obj)         }           tableview.reloaddata()     }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }      // mark: - table view data source      //create number of rows based on count of objects array     override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {         print ("objects count")         print (objects.count) //prints 38         return objects.count     }      override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {  var cell:uitableviewcell = self.tableview.dequeuereusablecellwithidentifier("cell")! uitableviewcell          let object = objects[indexpath.row]          cell.textlabel?.text =  object["tagname"]!          return cell     } 

any suggestions?

that because marked tableview's content property "static cells". need set tableview's content "dynamic prototypes". can tableview attributes inspector -> choose "dynamic prototypes on first property "content".

enter image description here


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -