ios - fatal error: Array index out of range with Parse.com -
i have application swift 2 , parse.com. added uisearchcontroller, , when use it, application crash. , shows error "fatal error: array index out of range"
.
there error in string "if var pffiltered = dataforsearchcontroller?[indexpath.row]" exc_bad_instruction
when touch in search bar.
override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath, object: pfobject?) -> pftableviewcell? { var searchtext = searchcontroller.searchbar.text let cellindentifier: string = "newscell" var cell: parsetableviewcell? = tableview.dequeuereusablecellwithidentifier(cellindentifier) as? parsetableviewcell if searchcontroller.active == false { if (cell == nil) { cell = parsetableviewcell(style: uitableviewcellstyle.default, reuseidentifier: cellindentifier) } if let pfobject = object { //cell?.textlabel?.text = pfobject["textnews"] as? string cell?.labelnametext?.text = pfobject["namenews"] as? string // name cell?.labeldatatext?.text = pfobject["datenews"] as? string // data cell?.labeltext = pfobject["textnews"] as? string cell?.labelurlnews = pfobject["urlnews"] as? string // link on site news var imagefromparse = object?.objectforkey("imagenews") as? pffile imagefromparse?.getdatainbackgroundwithblock({ (imagedata: nsdata?, error: nserror?) -> void in var image: uiimage! = uiimage(data: imagedata!)! cell?.imageviewcell.image = image }) } } else { if var pffiltered = dataforsearchcontroller?[indexpath.row] { cell?.labelnametext?.text = pffiltered["namenews"] as? string cell?.labeldatatext?.text = pffiltered["datenews"] as? string cell?.labeltext = pffiltered["textnews"] as? string cell?.labelurlnews = pffiltered["urlnews"] as? string var imagefromfilteredparse = object?.objectforkey("imagenews") as? pffile imagefromfilteredparse?.getdatainbackgroundwithblock({ (imagedatatwo: nsdata?, error: nserror?) -> void in var imagetwo: uiimage = uiimage(data: imagedatatwo!)! cell?.imageviewcell.image = imagetwo }) } } return cell }
override func numberofsectionsintableview(tableview: uitableview) -> int { return 1 } override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { var query: pfquery = pfquery(classname: "newsnow") if self.dataforsearchcontroller == nil { return objects?.count ?? 0 } else { return dataforsearchcontroller?.count ?? 0 } }
Comments
Post a Comment