私は友人の配列、それらの関連情報の配列を持っています。私はテーブルビューでセルをレンダリングしていますが、これは素晴らしいです。私は画面上のすべてをクリックしてたくさんの上/下にスクロールすると、アプリをクラッシュさせることができます...そして私は私の人生のために理由を理解できません!Swift - UITableVewControllerの範囲外のインデックス
これはエラーです:致命的なエラー:インデックスが範囲外
は、この問題が発生した理由として韻か理由があるように思えませんし、それは本当に紛らわしいです。洞察は高く評価されます。
これは失敗クラスです:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! PictureCell
let pos = self.positiveVoteArray.reduce(0,combine: {$0 + $1})
let neg = self.negativeVoteArray.reduce(0,combine: {$0 + $1})
let progress = (pos + neg)/pos
//Fails below this line, first reference to indexPath.row //
cell.usernameBtn.setTitle(usernameArray[indexPath.row], forState: .Normal)
cell.uuidLbl.text = uuidArray[indexPath.row]
avaArray[indexPath.row].getDataInBackgroundWithBlock { (data:NSData?, error:NSError?) in
if error == nil {
cell.avaImg.image = UIImage(data: data!)
}
}
if votedFriendsArray.contains((PFUser.currentUser()?.username!)!) {
cell.scoreBar.hidden = false;
cell.dislikeBtn.hidden = true;
cell.likeBtn.hidden = true;
cell.scoreBar.setProgress(progress, animated: true)
} else {
cell.scoreBar.hidden = true;
cell.dislikeBtn.hidden = false;
cell.likeBtn.hidden = false;
}
picArray[indexPath.row].getDataInBackgroundWithBlock { (data:NSData?, error:NSError?) in
if error == nil {
cell.picImg.image = UIImage(data: data!)
}
}
// assign index
cell.usernameBtn.layer.setValue(indexPath, forKey: "index")
return cell
}
どのラインにエラーが表示されますか? –
@SamMエラーがコメントの下にある、8行目 – matt