swift - Array list item count and number of element in an array mismatch while using swiftyjson? -
import uikit import alamofire import swiftyjson class recentadded: uiviewcontroller ,uitableviewdatasource,uitableviewdelegate{ @iboutlet var tableview: uitableview! var list:json! var sendurl:string! override func viewdidload() { super.viewdidload() alamofire.request(.get, "http://api.dirble.com/v2/stations/recent", parameters: ["token": "260674ecb51572a8faa4e77199"]) .responsejson { response in if let json = response.result.value { self.list = json(data: response.data!) print(self.list) /// showing less element if element more 25 self.tableview.datasource = self self.tableview.delegate = self self.tableview.reloaddata() print(self.list.arrayvalue.capacity) // printing actual capacity } } // additional setup after loading view. } func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return self.list.arrayvalue.capacity } func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("cell") as! recentcelltableviewcell let samplearray = self.list.array let imageurl:string! = samplearray![indexpath.row]["image"]["thumb"]["url"].stringvalue if imageurl != ""{ alamofire.request(.get, imageurl).responseimage { (response) -> void in guard let image = response.result.value else { return } cell.img!.image = image } }else{ cell.img!.image = uiimage(named: "rad")! } cell.nm?.text = samplearray![indexpath.row]["name"].stringvalue let catarr = samplearray![indexpath.row]["categories"].array let des:string! = "category : " + catarr![0]["title"].stringvalue + " " + "slug : " + catarr![0]["slug"].stringvalue cell.des?.text = des return cell } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { let cell = tableview.cellforrowatindexpath(indexpath) as! recentcelltableviewcell let samplearray = self.list.array let url = samplearray![indexpath.row]["streams"].array sendurl = url![0]["stream"].stringvalue self.performseguewithidentifier("next", sender: self) } override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { // if (segue.identifier == "next") { // initialize new view controller , cast view controller var viewcontroller = segue.destinationviewcontroller as! player viewcontroller.urll = sendurl } } }
my problem when printing list.arrayvalue.capacity showing actual size of array correct when tried print element of array show's less element counting. not sure wrong in code????/
the main problem in printing element. not printing elements.
i think you're confusing array capacity actual item count. numberofrowsinsection
, use count
property of array instead:
func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return self.list.arrayvalue.count }
more details count vs. capacity in answer: swift array.capacity vs array.count
Comments
Post a Comment