У меня есть массив друзей, массивы их связанной информации. Я создаю ячейки в виде таблицы, и это отлично работает. Я могу заставить приложение потерпеть крах, хотя, если я прокручу вверх/вниз с большим количеством щелчков по всему экрану ... и я не могу на всю жизнь понять, почему!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