0
我有夫特2和Parse.com的應用程序。我添加了UISearchController,當我使用它時,應用程序崩潰。它顯示了一個錯誤"fatal error: Array index out of range"
。致命錯誤:數組索引超出範圍與Parse.com
有串"if var pfFiltered = dataForSearchController?[indexPath.row]" is EXC_BAD_INSTRUCTION
一個錯誤,當我在搜索欄中觸摸。
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 a site with 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
}
可以看到的是使用之前它indexPath.row'的'價值? – donjuedo
不,我沒看見。 – Alexander
你爲什麼不查了一下indexPath.row的值是???它說:「數組索引超出範圍」所以,如果你有你的數組中的5種元素和indexPath.row是10那麼很明顯,這是問題,不是嗎? – Gruntcakes