ios - Uploading music through parse return "fatal error: Array index out of range" -
import uikit import parse import bolts import avfoundation import avkit public var audioplayer = avplayer() public var selectedsongnumber = int() class tableviewcontroller: uitableviewcontroller, avaudioplayerdelegate{ var idarray = [string]() var namearray = [string]() override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. var objectidquery = pfquery (classname: "songs") objectidquery.findobjectsinbackgroundwithblock({ (objectsarray: [anyobject]?, error: nserror?) -> void in var objectids = objectsarray as! [pfobject] nslog("\(objectids)") in 0...objectids.count-1{ self.idarray.append(objectids[i].valueforkey("objectid") as! string) self.namearray.append(objectids[i].valueforkey("songname") as! string) self.tableview.reloaddata() } }) } func grabsong(){ var songquery = pfquery(classname: "songs") songquery.getobjectinbackgroundwithid(idarray[selectedsongnumber], block: { (object : pfobject?, error : nserror?) -> void in if let audiofileurltemp = object?.objectforkey("songfile")?.url{ audioplayer = avplayer(url: nsurl(string: audiofileurltemp!)) audioplayer.play() } }) } override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return idarray.count } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { var cell = tableview.dequeuereusablecellwithidentifier("cell") as! uitableviewcell cell.textlabel?.text = namearray[indexpath.row] return cell } override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { selectedsongnumber = indexpath.row grabsong() } }
Comments
Post a Comment